Reputation: 93
I'd like to iterate over an array inside a JSON file by index using bash jq, and get for example only the name from each object inside that array:
{
"items": [
{
"name": "item1",
"year": "2021"
},
{
"name": "item2",
"year": "2020"
}
]
}
Any ideas on how to achieve something like this?
item1name=`jq '.items'<???????> object.json | sed "s/\"//g"`
Upvotes: 0
Views: 1992
Reputation: 65105
You can use
jq -r '.items[] | .name' object.json
where -r
option is used to remove double quotes wrapping up the name values.
Upvotes: 1