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


>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"}}'

Leave a Reply Cancel reply