Skip to content

Latest commit

 

History

History
106 lines (83 loc) · 1.65 KB

File metadata and controls

106 lines (83 loc) · 1.65 KB

Convertrr

Transition between JSON and CSV formats.

  • CSV to JSON
  • JSON to CSV

Usage

A simple command-line tool to convert CSV files to JSON format and vice versa.
The schema is defined in an external file to enable generic file conversion.

Usage:
  convertrr [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  csvtojson   Convert a CSV file to JSON format
  help        Help about any command
  jsontocsv   Convert a JSON file to CSV format

Flags:
  -h, --help   help for converter

Use "convertrr [command] --help" for more information about a command.

Schema Definition

Define a schema called test.schema.

[
  {
    "name": "id",
    "jsonTag": "id",
    "csvHeader": "id",
    "type": "string",
    "required": true
  },
  {
    "name": "title",
    "jsonTag": "title",
    "csvHeader": "title",
    "type": "string",
    "required": true
  }
]

CSV to JSON

  1. Create an input file input.csv
id,title
"id001","Arsenal"
"id002","Chelsea"
"id003","Brighton"
  1. Convert CSV to JSON based on schema.json

Take the input CSV and use the schema to translate.

convertrr csvtojson -i input.csv -o output.json -s test.schema

EXPECTED OUTPUT

{
  "data": [
    {
      "id": "id001",
      "title": "Arsenal"
    },
    {
      "id": "id002",
      "title": "Chelsea"
    },
    {
      "id": "id003",
      "title": "Brighton"
    }
  ]
}

JSON to CSV

Convert JSON to CSV based on schema.json

convertrr jsontocsv -i input.json -o output.csv -s schema.json

EXPECTED OUTPUT

id,title
id001,Arsenal
id002,Chelsea
id003,Brighton