Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How do I print a parent value of an object when I am already deep into the object's children?

$
0
0

Say I have the following JSON, stored in my variable jsonVariable.

{"id": 1,"details": {"username": "jamesbrown","name": "James Brown"    }}

I parse this JSON with jq using the following:

echo $jsonVariable | jq '.details.name | select(.name == "James Brown")'

This would give me the output

James Brown

But what if I want to get the id of this person as well? Now, I'm aware this is a rough and simple example - the program I'm working with at the moment is 5 or 6 levels deep with many different JQ functions other than select. I need a way to select a parent's field when I am already 5 or 6 layers deep after carrying out various methods of filtering.

Can anyone help? Is there any way of 'going in reverse', back up to the parent?


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>