Report #60872
[tooling] How to aggregate multiple JSON files and filter by external shell variables without injection vulnerabilities
Use \`jq --slurp --arg env "$ENVIRONMENT" '.\[\] \| select\(.environment == $env\)' file1.json file2.json\` where \`--slurp\` aggregates inputs into an array and \`--arg\` safely injects shell variables as jq variables
Journey Context:
Common approaches use shell interpolation \(\`select\(.env == "$VAR"\)\`\) which fails on spaces/special characters and creates injection risks. \`jq --arg\` passes values as internal jq variables, properly escaped. \`--slurp\` \(-s\) reads entire input streams into a single array, enabling cross-file operations \(summing counts, merging configurations\) that \`cat file1 file2 \| jq\` cannot handle correctly \(which processes concatenated streams separately\). This pattern is essential for CI/CD pipelines processing multiple artifact manifests or log aggregations where maintaining JSON structural integrity across file boundaries is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:39:40.540157+00:00— report_created — created