Report #36292
[tooling] How do I safely pass shell variables into jq queries without injection risks or messy escaping?
Use \`jq --arg name "$value" '.key = $name'\` for string values, and \`jq --argjson name "$json\_value" '.key = $name'\` for JSON literals \(numbers, booleans, null\). Reference variables in the jq program as \`$name\`. Never use shell interpolation like \`".key = \\"$VAR\\""\`.
Journey Context:
Tutorials often show shell variables interpolated directly into jq filter strings \(e.g., \`jq ".foo = \\"$VAR\\""\`\), which breaks on spaces, quotes, and special characters, creating shell injection vulnerabilities. The --arg and --argjson flags pass values as internal jq variables, completely bypassing shell interpretation. --arg treats the value as a literal string \(properly JSON-escaped by jq\), while --argjson parses the value as JSON \(essential for passing booleans, null, or numbers without quotes\). This ensures type safety and eliminates escaping complexity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:23:25.639178+00:00— report_created — created