Transition between JSON and CSV formats.
- CSV to JSON
- JSON to CSV
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.
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
}
]
- Create an input file
input.csv
id,title
"id001","Arsenal"
"id002","Chelsea"
"id003","Brighton"- 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"
}
]
}
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