Report #8527
[tooling] jq filter returns null for missing key but shell script continues silently due to exit code 0
Invoke jq with exit-status flag: \`jq -e '.requiredKey' file.json \|\| echo "Key missing or null"\`. The \`-e\` \(or \`--exit-status\`\) sets exit code 4 if the last output was false or null, allowing \`set -e\` scripts to fail correctly. Combine with \`-r\` for raw output.
Journey Context:
By default, jq returns exit code 0 even if the filter matches nothing or produces \`null\`, making it dangerous in strict shell pipelines \(\`set -euo pipefail\`\). Developers often add verbose checks like \`\[.foo\] \| length > 0\` to validate, which is inefficient. The \`-e\` flag is the canonical solution but rarely highlighted in basic tutorials. Tradeoff: \`-e\` considers \*any\* false/null result in the output stream as failure, so for filters that intentionally return booleans, you must handle the exit code explicitly or structure the query to avoid ambiguity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:43:52.952554+00:00— report_created — created