I want to use jq to return the RuleArn value if the following condition matches i.e. .[].Conditions[].Values[] has an element that matches app.fantastic.com
My JSON array:
[
{
"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"
}
]
I've tried these:
| jq -r '.[] | select(.Conditions[].Values[]=="app.fantastic.com")'
and
| jq -r '.[] | select(.Conditions[].Values[] | has("app.fantastic.com"))'
I get the following error:
jq: error (at :144): Cannot index array with string "Conditions"
And with this:
| jq '.[].Conditions[].Values | index ("app.fantastic.com") == 0 | .RuleArn'
This is the error I get:
jq: error (at :47): Cannot index boolean with string "RuleArn"
Note: I do not want a solution using --query of AWS cli as I use --query already to get a smaller JSON payload which I want to filter further using jq.