The command will transform the json file users.json in csv, users.csv.
The json has an array named items
that contains different fields, here we select only id, name and the array perms.
the tostring
filter is applied to flatten the array perms
{
"items": [
{
"id": "j_doe",
"name": "Jon Doe",
"perms": [
30,
104,
102,
]
},
]
}
jq -r '.items[] | [.id, .name, (.perms | length), .perms | tostring] | @csv' users.json >> users.csv