I have a weird CSV with one column being JSON data of quite a large size and one is a name. Showing proper JSON formatting for clarity, but file is flat with no new line chars.
name,
{
"field1":
{"name":"foo",
"email":"[email protected]"},
"field2":{
"subfield":{
"subfield2":{
"active":1,
"passive":11,
"running":111
}
}
}
}
I am trying to get the name and all unique values for the subfield 2 into a output (ideally CSV).
name,
active passive running
The issue is that the number of fields is not constant and the names of the subfields are not constant either. I have tried using jq, Miller, and sed/awk without much luck since it combines a huge JSON blob and CSV data.
2
Answers
If you run in your sample input
you get
The sample output you write, is wrong, because if it’s a one field CSV, you do not have the
,
after name, there are no other fieldsBut I probably didn’t understand what you want
You could use your favorite CSV-to-TSV translator to convert the CSV to TSV and then run it through jq like so: