I have a file that looks as below:
{
"repositories": [
{
"id": "156c48fc-f208-43e8-a631-4d12deb89fa4",
"namespace": "rhel12",
"namespaceType": "organization",
"name": "rhel6.6",
"shortDescription": "",
"visibility": "public"
},
{
"id": "f359b5d2-cb3a-4bb3-8aff-d879d51f1a04",
"namespace": "rhel12",
"namespaceType": "organization",
"name": "rhel7",
"shortDescription": "",
"visibility": "public"
}
]
}
I want to get only name values with each of them in a new line so that I can use while read -r line
.
I need only
rhel6.6
rhel7
I am using jq as follows which doesn't seem to work:
jq -r '.[].name'
Please suggest correct use of jq here
You need to combine filters by means of
|
operator:The first
.[]
fetchesrepositories
array. The next.[]
fetches all the items of therepositories
array. Finally,.name
extracts properties from the array items(objects).Note, the first
.[]
works on object because it is a documented feature:You want to look at the repositories array instead of treating the input as an array:
Here is another solution. Assuming the requirements
if the data is in
data.json
then the commandshould produce