Using jq to fetch key value from json output
You need to combine filters by means of |
operator:
$ jq -r '.[] | .[] | .name' test.json
rhel6.6
rhel7
The first .[]
fetches repositories
array. The next .[]
fetches all the items of the repositories
array. Finally, .name
extracts properties from the array items(objects).
Note, the first .[]
works on object because it is a documented feature:
.[]
If you use the .[index] syntax, but omit the index entirely, it
will return all of the elements of an array...
You can also use this on an object, and it will return all the
values of the object.
You want to look at the repositories array instead of treating the input as an array:
$ jq -r '.repositories[].name' file
rhel6.6
rhel7