Report #51773
[tooling] How to safely pass shell variables into jq filters without injection or quoting issues?
Use \`jq --arg varname "$SHELL\_VAR" '.key = $varname'\` for string values, and \`jq --argjson varnum "$NUM" '.count = $varnum'\` for numbers/booleans/null. Reference variables with \`$name\` in the filter, never using shell interpolation.
Journey Context:
String interpolation like \`jq '.key = \\"'"$VAR"'\\"'\` breaks on quotes and spaces, creating shell injection vulnerabilities and brittle scripts. \`--arg\` guarantees safe literal string insertion, while \`--argjson\` parses the value as JSON \(essential for non-strings\). This is the only robust way to combine dynamic shell data with jq in automated scripts, eliminating quoting hell entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:23:48.112276+00:00— report_created — created