嗨,我正在尝试使用 jq 解析下面的哈希
值{
"name": "a",
"data": [
{
"sensitive": false,
"type": "string",
"value": "mykeypair"
},
{
"sensitive": false,
"type": "int",
"value": 123
}
]
}
并获得类似
a,string,mykeypair
a,int,123
我能够得到这样的输出
a,string,mykeypair
a,int,mykeypair
a,string,123
a,int,123
jq
解决方案:
jq -r '.name as $n | .data[] | [$n, .type, .value] | @csv' file.json
输出:
"a","string","mykeypair"
"a","int",123
如果必须输出不带引号的值:
jq -r '.name as $n | .data[] | [$n, .type, "(.value)"] | join(",")' file.json
输出:
a,string,mykeypair
a,int,123