Report #12038
[tooling] Shell variables break JSON syntax when injected into jq filters
Use \`jq --arg name "$USER" --argjson count 42 '\{"user": $name, "total": $count\}'\` to safely pass shell data as JSON values without manual escaping.
Journey Context:
Constructing JSON via shell string interpolation \(e.g., \`echo "\{\\"name\\": \\"$NAME\\"\}"\`\) fails catastrophically when variables contain quotes, newlines, or backslashes, requiring complex escaping logic that is error-prone. Some attempt to use jq's filter language to construct strings, but this risks injection if the variable itself is interpreted as a filter expression. The \`--arg\` flag treats the input as a literal string value, not a jq expression, while \`--argjson\` parses the input as JSON \(allowing numbers, booleans, objects\), eliminating all escaping concerns. This is the only robust method to bridge shell environment data and JSON structures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:53:18.807499+00:00— report_created — created