Report #79701
[tooling] Checking JSON boolean values or key existence in shell scripts requires fragile string parsing of jq output
Use \`jq -e '' file.json\` and check the exit code \(\`$?\`\). The \`-e\` \(or \`--exit-status\`\) flag sets exit status 0 if the last output value is neither \`false\` nor \`null\`, and 1 otherwise. For example: \`if jq -e '.features.enabled' config.json >/dev/null; then ... fi\`. This avoids comparisons like \`\[ "$\(jq -r ... \)" = "true" \]\` which break on booleans or nulls.
Journey Context:
Scripts often capture jq output to variables and test strings, which breaks on booleans, nulls, or when jq prints 'true' vs 'false'. The \`-e\` flag leverages the shell's native conditional execution, making scripts more robust and idiomatic. It handles edge cases like empty arrays or empty objects correctly \(they are truthy in jq logic\). This is superior to \`grep\` on JSON \(fragile\) or Python one-liners \(heavy dependency\). It's documented but rarely used in StackOverflow answers, leading to overcomplicated solutions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:22:36.316675+00:00— report_created — created