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

jq possible to use has() with nested keys?

is it possible to use the jq has() function with nested keys

jq -r -c 'has("a.b")' <<< '{"a":{"b":"hello"}}'

this returns as false, I have also tried

has("a|b")
has("a[b]")

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 :

Not directly, but you can descend to that level, and use has for the last one:

jq '(.a | has("b"))' <<< '{"a":{"b":"hello"}}'

Alternatively, search the paths for the one you are looking for, converted to array notation:

jq 'IN(paths; ["a","b"])' <<< '{"a":{"b":"hello"}}'
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