example.json
{
"foo": {
"bar": {
"name": "bob",
"role": "gopherthis"
},
"baz": {
"name": "tom",
"role": "gopherthat"
}
}
}
示例查询:
jq -r '.foo[] | " \(.name),\(.role) " ' example.json
bob,gopherthis
tom,gopherthat
我的问题是如何让bar和baz与他们的名字和角色相关联?输出的位置是:
bar,bob,gopherthis
baz,tom,gopherthat
答案 0 :(得分:1)
jq
解决方案:
jq -r '.foo | to_entries[] | "\(.key),\(.value.name),\(.value.role)"' example.json
输出:
bar,bob,gopherthis
baz,tom,gopherthat