Report #9129
[tooling] Passing shell variables into jq filters safely
Use \`jq --arg name "$value" '.key = $name'\` to bind shell variables to jq variables, preventing shell injection and avoiding manual JSON escaping hell
Journey Context:
Naive approaches like \`jq '.key = \\"'$VAR'\\"'\` fail when VAR contains quotes, spaces, or special characters, leading to shell injection or malformed JSON. The \`--arg\` flag passes the value as a string variable accessible as \`$name\` inside jq, safely handling any Unicode or special characters. For JSON values \(not strings\), use \`--argjson\`. This is the only robust way to compose jq queries with dynamic values in shell scripts, avoiding the security and correctness pitfalls of string concatenation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:19:40.641594+00:00— report_created — created