I would like to convert 500+ json files to csv format using the solution provided in How to convert arbirtrary simple JSON to CSV using jq? but my json files are not in the same format as per the proposed solution.
Following represents a sample json file:
[
{
"jou_entry": {
"id": 655002886,
"units": 2
}
},
{
"jou_entry": {
"id": 655002823,
"units": 4
}
},
{
"jou_entry": {
"id": 657553949,
"units": 6
}
}
]
Where as the proposed solution requires the json in the following format:
[
{
"id": 655002886,
"units": 2
},
{
"id": 655002823,
"units": 4
},
{
"id": 657553949,
"units": 6
}
]
I am able to convert the json from source format to required format using the following jq filter
jq -r '[.[] | ."jou_entry"]'
But I don't like the hard-coding of key "jou_entry" in the filter. As this will require individual key definition for so many files. I would like to have the conversion without the hard-coded value.
How can I do this? Please help