Reputation: 2565
I have the following JSON file:
{
"foo": {
"name": "Name 1",
"color": "green",
"something_else": {
"name" : "Name 2"
}
},
"bar": {
"name": "Name 3",
"color": "red"
}
}
How to get the proprety name foo
from "Name 2"
using jq ?
I tried
.[] |select(."name"=="Name 2")
And how to get a list [foo,bar]
(all main parents) from the property name name
?
Upvotes: 1
Views: 192
Reputation: 157947
Like this:
jq 'path(recurse|select(.name?=="Name 2"))[0]' file.json
Upvotes: 1