[英]json parsing using jq
I am trying to parse a JSON file我正在尝试解析 JSON 文件
input content:输入内容:
{
"pools":[
{
"id":"403add1f-25d9-4a24-99ff-12c5559fecfa",
"members":[
{
"id":"2b8e1155-aae0-4999-a038-ec900fd8e5b6"
},
{
"id":"3010bc81-e76d-462a-b4cc-2dc0888d65d2"
}
]
},
{
"id":"ranj-25d9-4a24-99ff-12c5559fecfa",
"members":[
{
"id":"ranj-aae0-4999-a038-ec900fd8e5b6"
}
]
}
],
"pools_links":[
]
}
Expected output:预期 output:
403add1f-25d9-4a24-99ff-12c5559fecfa=2
ranj-25d9-4a24-99ff-12c5559fecfa=1
the '403add1f-25d9-4a24-99ff-12c5559fecfa' is reading from the id, and the 2 is the number of members. '403add1f-25d9-4a24-99ff-12c5559fecfa' 是从 id 读取的,2 是成员数。
Does anyone have an idea of how to do it in one jq call?有谁知道如何在一个 jq 调用中做到这一点?
Thanks.谢谢。
Easy enough:很简单:
jq -r '.pools[] | "\(.id)=\(.members|length)"'
-r
turns on raw (non-JSON) output so that we can format the output line directly. -r
打开原始(非 JSON) output 以便我们可以直接格式化 output 行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.