这是一些示例JSON:
{
"Tags": [
{
"Key": "Name",
"Value": "foo"
},
{
"Key": "Type",
"Value": "C"
}
]
}
我只想在“键”为“类型”时打印“值”的值。所以它应该打印出“C”。这是我到目前为止。
echo $MY_TAGS | jq 'if .Tags[].Key == "Type" then .Tags[].Value else empty end'
但它打印出来:
“富”
“C”
有没有办法做到这一点?
最佳答案
试试这个:
.Tags[] | select(.Key == "Type") | .Value
关于json - 根据另一个键的值有条件地打印值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25001349/