Reputation: 359
Let's say I have the following JSON output:
{
"Stacks": [
{
"StackName": "hello-world",
"Tags": [
{
"Key": "environment",
"Value": "sandbox"
},
{
"Key": "Joe Shmo",
"Value": "Dev"
}
]
},
{
"StackName": "hello-man",
"Tags": [
{
"Key": "environment",
"Value": "live"
},
{
"Key": "Tandy",
"Value": "Dev"
}
]
}
]
}
How would I write a jq
query to grab all StackName
s for stacks that do NOT have a Tags
value "Key": "Joe Shmo"
? So the result would return simply hello-man
.
Upvotes: 1
Views: 53
Reputation: 116740
.Stacks[]
| select( any(.Tags[]; .Key == "Joe Shmo" ) | not)
| .StackName
This checks for equality efficiently (any
has short-circuit semantics), whereas contains
would check for containment.
Upvotes: 1