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

yq filter with select from different map/list

example_a:
  - key: sa01
    name: sa

match_a:
  sa_key: sa01

This one works:

yq '.example_a[] |select(.key == "sa01")' 

Is it possible to make it work this way:

yq '.example_a[] |select(.key == .match_a.sa_key)'

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 :

Yes, that’s possible using a variable on the key:

yq '.match_a.sa_key as $key | .example_a[] |select(.key == $key)' i.yaml

So we save .match_a.sa_key as the var $key, so that we can use that in the select() directly


Output:

key: sa01
name: sa
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