Using jq , how to select a parent if it contains a child that meets two filter requirements?
In this example, I want to highlight all Subnets that have a child tag with the key "Name" and the value "TheName". My example consists of two subnets. The first has "TheName" in the wrong way. The second subnet has the name / value pair that I am looking for. those. "Key": "Name", "Value": "TheName"
Next, select the subnet with the specified value in one of the tags, but not in pairs. It returns both subnets instead of the second subnet.
jq '.Subnets[] | select(.Tags[].Value=="TheName")' output
How to use jq to select only subnets that have the name / value pair I'm looking for?
{ "Subnets": [ { "VpcId": "vpc-12345678", "SubnetId": "subnet-1234567a", "Tags": [ { "Key": "IgnoreThis", "Value": "TheName" }, { "Key": "Name", "Value": "NotTheName" } ] }, { "VpcId": "vpc-12345678", "SubnetId": "subnet-1234567b", "Tags": [ { "Key": "IgnoreThis", "Value": "ignore" }, { "Key": "Name", "Value": "TheName" } ] } ] }
Desired Result:
{ "VpcId": "vpc-12345678", "SubnetId": "subnet-1234567b", "Tags": [ { "Key": "IgnoreThis", "Value": "ignore" }, { "Key": "Name", "Value": "TheName" } ] }
source share