Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find the parent yaml node of an array element using yq

Assuming I have a yaml file more or less like this

foo:
 - element1
 - element2
bar: 
 - element3
 - element4

What is the yq command to get the parent of element4 (I want to get bar)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

to_entries | .[] | select(.value[] | contains("element4")).key

Will loop over the result of to_entries, search where .value contains element4, and logs .key of the result.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading