Let's say I have the following JSON stored in my jsonVariable variable.
{ "id": 1, "details": { "username": "jamesbrown", "name": "James Brown" } }
I am analyzing this JSON with jq using the following:
echo $jsonVariable | jq '.details.name | select(.name == "James Brown")'
It will give me a way out
James brown
But what if I also want to get this personβs ID? Now I know that this is a crude and simple example - the program I'm working with now has a depth of 5 or 6 levels with many different JQ functions besides select. I need a way to select the parent field when I am already 5 or 6 layers deep after performing various filtering methods.
Can anybody help? Is there any way to "go back" to the parent? (Not sure I make sense!)
json jq
Xenidious
source share