Convert a JSON array to CSV with a header row
convert json to csv command line | jq json to csv with header | save api output as spreadsheet | jq | json | csv | exportCaution: This command changes the system. Understand what it does before you run it.
jq -r '(.[0] | keys_unsorted) as $k | $k, (.[] | [.[$k[]]]) | @csv' plugins.json > plugins.csvReads the keys of the first object as column names, prints them as the first line and then, for each object, the values in the same order. @csv quotes strings and correctly escapes embedded quotes. This is handy for preparing wp plugin list --format=json for a spreadsheet, for example.
Note: If fields contain nested objects or arrays, @csv aborts with an error. An existing target file is overwritten.
Also searched as
- convert json to csv command line
- jq json to csv with header
- save api output as spreadsheet