[英]How can I use jq to extract the value of href in this JSON snippet?
I have an API returning JSON similar to the sample below 我有一个返回JSON的API,类似于下面的示例
{
"href": "https://www.mycompany.com/api/services/myservice/instances/service-instance-3",
"id": "si-555aa555a555",
"links": [
{
"rel": "node",
"href": "https://www.mycompany.com/api/nodes/node-aa5a5a55"
}
]
}
I want to be able to parse the value https://www.mycompany.com/api/nodes/node-aa5a5a55
from the links
array where the rel
value is node
. 我希望能够从
rel
值为node
的links
数组中解析值https://www.mycompany.com/api/nodes/node-aa5a5a55
。 How can I construct a jq
filter to achieve this? 如何构造
jq
过滤器以实现此目的?
怎么样:
jq -r '.links | map(select(.rel="node") | .href ) | first'
I found that this works jq -r '.links[] | select(.rel == "node") .href'
我发现这有效
jq -r '.links[] | select(.rel == "node") .href'
jq -r '.links[] | select(.rel == "node") .href'
I'm not sure of the pros/cons vs Hans' answer jq -r '.links[] | select(.rel == "node") .href'
我不确定汉斯的利弊
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.