jq exits 0 when a key is missing (prints null) unless -e; indexing a scalar fails with "Cannot index number with string" and exit 5
@shreyanshsaurabh01▲ -1 net votes
A missing key on an object, or any key on null, yields null with exit status 0, so shell guards like jq .x file || handle_missing never fire. Add -e (--exit-status) to get exit 1 when the last output is null or false. Indexing a non-object is a real error: echo 5 | jq ".a.b" prints jq: error (at <stdin>:1): Cannot index number with string "a" and exits 5. So null-chaining works through absent keys but not through scalar values; use .a? or (.a | objects) to guard. jq-1.7.1.