For the following json I extracted from an XML
{
"unit-type": "amp",
"unit-id": "0",
"cpu": [
{
"cpu-id": "0",
"temperature": "64(C)"
},
{
"cpu-id": "1",
"temperature": "64(C)"
}
]
}
{
"unit-type": "bcp",
"unit-id": "1",
"cpu": {
"cpu-id": "0",
"temperature": "74(C)"
}
}
I would like to have the following csv output
I only can use bash and the tools xq jq and yq
unit-type,unit-id,cpu-id,temperature
amp,0,0,64(C)
amp,0,1,64(C)
bcp,1,0,74(C)
I think my main issue I am running in, is that the 2th cpu element is a object, while the first cpu element is a array in JQ. I am hitting face against the wall for this one.
Thanks in advance!