To convert json to csv with headers using jq
and the @csv
filter.
jq -r '[first|keys_unsorted] + map([.[]]) | .[] | @csv' example.json > converted.csv
This would work on a simple json structured like:
[
{
"dealName": "Example 1",
"filename": "example1.txt",
"dealId": 12345,
"documentId": 67890
},
{
"dealName": "Example 2",
"filename": "example2.txt",
"dealId": 23456,
"documentId": 45678
}
]
Output:
"dealName","filename","dealId","documentId"
"Example 1","example1.txt",12345,67890
"Example 2","example2.txt",23456,45678