Using jq
I try to convert a JSON to CSV. Here's how my input JSON looks like:
{
"rows": [
{
"a": ["x","y"],
"b": "some",
"c": "string"
},
{
"a": ["u","v"],
"b": "another",
"c": "string"
}
]
}
The desired output is like:
a | b | c
x y | some | string
u v | another | string
Edit: And for those complaining that this wouldn't be valid CSV, here in RFC 4180 compliant syntax:
a,b,c
x y,some,string
u v,another,string
Using .rows
, I successfully get the array:
[{"a":["x","y"],"b":"some","c":"string"},{"a":["u","v"],"b":"another","c":"string"}]
But .rows | @csv
says: object ({"a":["x","...) is not valid in a csv row
. So, I somehow have to join the array in key "a".
Using .rows[] | .a | join(" ")
I get:
"x y"
"u v"
But how do I get this back into my JSON to then use ... | @csv
to get my desired CSV data?