Report #15720
[tooling] Aggregating multiple JSON files and safely injecting shell variables into jq filters
Use \`jq --slurp --arg env "$ENV\_VAR" '.\[\] \| select\(.name == $env\)' file1.json file2.json\` to read all files into an array and safely use shell variables without injection risks, then process with array iteration.
Journey Context:
Developers often pipe jq commands together or use unsafe string interpolation like \`jq ".foo == \\"$VAR\\""\` which breaks on special characters or quotes. The \`--arg\` flag passes values as variables accessible via \`$name\`, while \`--argjson\` parses the value as JSON \(for numbers/booleans\). \`--slurp\` \(\`-s\`\) reads all input files into a single array \`\[...\]\`, enabling cross-file operations like summing values across log files. Common mistake: forgetting that \`-s\` changes the input structure from a stream of objects to an array of objects, requiring \`.\[\]\` to iterate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:50:29.026474+00:00— report_created — created