Report #12690
[tooling] Passing shell variables into jq queries results in syntax errors or injection vulnerabilities from unescaped strings
Use jq --arg name "$value" '.key = $name' to bind shell variables as jq variables, or --argjson for numbers/booleans, ensuring proper JSON typing and eliminating shell escaping complexity
Journey Context:
Tutorials often show ugly concatenation like jq '.foo = \\"'"$var"'\\"' which breaks on quotes and newlines. --arg treats the value as a literal string, while --argjson parses it as JSON \(crucial for true/false/null/numbers\). Common pitfall: using --arg when you need a number \(gets quoted \\"123\\" vs 123\); fix by using --argjson. This is the only safe way to handle arbitrary user input in jq. Alternative --slurpfile reads entire files into variables as arrays.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:44:03.382814+00:00— report_created — created