{
"content": [
{
"Title": "abc",
"brand": "xyz",
"size": "5 g",
"date": "2019-01-01",
"details": {
"Temperature": [
{
"value": "90",
"characteristics":"Normal"
},
{
"value":"100",
"characteristics":"high"
},
{
"value":"80",
"characteristics":"low"
}
],
"certifications": [
{
"value": "based",
"characteristics":"pass"
},
{
"value": "50",
"characteristics":"failed"
}
]
},
"formats": {
"city": "NYC",
"id": "007",
"manufacture":""
},
"innerDetails": [
{
"contains": "abc",
"panel":"xyz",
"values":[
{
"name":"abc",
"value":"10"
},
{
"name":"xyz",
"value":"20"
}
]
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但收到错误
无法用字符串“标题”索引数组
jq -r '.content[]|[.Title,.brand,.characteristics,.value]' $jsonfile. …
Run Code Online (Sandbox Code Playgroud) 我正在下载 api json 数据并将最终结果转换为 csv 文件。
样本数据格式如下:
{
"content": [{
"Title": "abc",
"brand": "xyz",
"information": {
"c1": "101",
"c2": "11111",
"c3": "a,b,c,d,e:abc."
}
},
{
"Title": "RX100",
"brand": "Yamaha",
"information": {
"c1": "102",
"c2": "22222",
"c3": "a."
}
},
{
"Title": "victor",
"brand": "TVS",
"information": {
"c1": "103",
"c2": "33333",
"c3": "a,b,c"
}
},
{
"Title": "R15",
"brand": "Yamaha",
"information": {
"c1": "104",
"c2": "44444",
"c3": "a,b"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我已经根据Title的数量成功下载并转换为多个csv。转换成多个 csv 文件后,数据如下所示。
Headers-> c1,c2,c3
csv1--> 101,11111,a,b,c,d,e:abc.
csv2--> 102,22222,a. …
Run Code Online (Sandbox Code Playgroud)