javapenguin
javapenguin

Reputation: 1036

Select object based on value of variable in json array using jq

I have the following json file:

 {
     "HostedZones": [
         {
             "Id": "Z3JX6LQV6IJO3E",
             "Name": "sandbox.mydomain.com."
         },
         {
             "Id": "Z13M9NFG2E4J5N",
             "Name": "internal.mydomain.com."
         }
     ]
 }

I am using jq and want to get the "Id" value of the object where 'Name' is 'internal.mydomain.com.'.

Upvotes: 1

Views: 173

Answers (1)

Inian
Inian

Reputation: 85580

Use select() filter on the name and get the id value with the following filter

jq '.HostedZones[] | select (.Name=="internal.mydomain.com.").Id'

Upvotes: 1

Related Questions