json2csv converts JSON to CSV.
You can easily define mappings for converts using XPath.
$ json2csv -i input.json -m mapping.json -o output.csv
The arguments are as follows.
Usage: json2csv [flags]
Flags
-i, --input string JSON input file path or directory or url
-m, --mapping string JSON to CSV mapping file path or url
-o, --output string CSV output file path
-b, --bom CSV with BOM
-h, --help Help
JSON and mapping files can be specified by URL.
json2csv -i https://github.com/onozaty/json2csv/raw/main/testdata/data/rss.json -m https://github.com/onozaty/json2csv/raw/main/testdata/mapping/rss.json -o output.csv
The conversion mapping definition is written in JSON.
Specify the position on the JSON with XPath.
{
"rowsPath": "//items/*",
"columns": [
{
"header": "title",
"valuePath": "/title"
},
{
"header": "link",
"valuePath": "/link"
},
{
"header": "description",
"valuePath": "/description"
}
]
}rowsPath: XPath to get as a rows.columns: Definition of each column.header: CSV header.valuePath: XPath to get as a value.useEvaluate: Specifytruewhen using an expression withvaluePath. For example, when usingsum()ornot(),boolean().
antchfx/xpath is used in json2csv.
See below for supported XPath.
For XPath in JSON, please refer to the following.
Please refer to the sample below.
You can download the binary from the following.
MIT