【发布时间】:2020-04-30 23:07:48
【问题描述】:
如果以下条件匹配,我想使用jq 返回RuleArn 值,即.[].Conditions[].Values[] 有一个匹配app.fantastic.com 的元素
我的 JSON 数组:
[
{
"Conditions": [
{
"Field": "http-header",
"HttpHeaderConfig": {
"Values": [
"dark"
],
"HttpHeaderName": "Environment"
}
},
{
"Values": [
"app.fantastic.com"
],
"Field": "host-header",
"HostHeaderConfig": {
"Values": [
"app.fantastic.com"
]
}
}
],
"IsDefault": false,
"Priority": "3",
"RuleArn": "iwantthisvalue"
}
]
我试过这些:
| jq -r '.[] | select(.Conditions[].Values[]=="app.fantastic.com")'
和
| jq -r '.[] | select(.Conditions[].Values[] | has("app.fantastic.com"))'
我收到以下错误:
jq:错误(在 :144):无法使用字符串“Conditions”索引数组
还有这个:
| jq '.[].Conditions[].Values | index ("app.fantastic.com") == 0 | .RuleArn'
这是我得到的错误:
jq: error (at :47): Cannot index boolean with string "RuleArn"
注意:我不想要使用 AWS cli 的 --query 的解决方案,因为我已经使用 --query 来获得更小的 JSON 有效负载,我想使用jq 进一步过滤它。
【问题讨论】: