Report #5567
[tooling] Shell variables containing JSON special characters break when interpolated into jq filters using double quotes
Use jq --arg name "$var" '.key = $name' to safely inject shell variables as JSON strings \(automatically escaped\), or --argjson for raw numeric/boolean values, avoiding all string interpolation
Journey Context:
The common anti-pattern is jq ".foo = \\"$var\\"" which fails catastrophically when $var contains quotes, backslashes, or newlines, creating injection vulnerabilities or syntax errors. --arg treats the variable as a literal JSON string, handling all escaping internally. For non-string values \(numbers, booleans, null\), --argjson parses the shell variable as JSON. Combined with --slurpfile for merging multiple JSON files into a variable \(as an array\), this allows complex transformations without creating temporary files or using unsafe eval patterns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:40:01.294920+00:00— report_created — created