Reputation: 1113
I have a json file with the below format. I want to extract the name
field value from inside based on the id
value.
so, if I pass id value as 99900, it should return me DEF. How can I do that using jq.
{
"11213-99900": {
"cid": "11213-99900",
"name": "DEF",
"id": "99900"
},
"11213-12345": {
"cid": "11213-12345",
"name": "ABC",
"id": "12345"
},
"11272-23456": {
"cid": "11272-23456",
"name": "YXX",
"id": "23456"
}
}
Upvotes: 0
Views: 63
Reputation: 50805
Use select
:
$ jq -r --arg q 99900 '.[] | select(.id == $q).name' file
DEF
Upvotes: 3