Report #65920
[tooling] Safely passing shell variables into jq queries without shell injection or quoting hell
Use \`jq --arg name "$VAR" '.key = $name'\` or \`--argjson\` for numbers/booleans. This binds the shell variable to a jq variable, avoiding string concatenation and escaping issues.
Journey Context:
The naive approach is \`jq ".key = \\"$VAR\\""\`, which breaks if \`$VAR\` contains quotes or newlines, leading to syntax errors or injection vulnerabilities. \`--arg\` treats the input as a literal string, safely escaped for JSON. \`--argjson\` parses the input as JSON \(useful for passing booleans/numbers\). This is the robust, production-safe pattern for shell-jq integration, preventing subtle bugs in data processing pipelines.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:07:31.628827+00:00— report_created — created