Report #5377
[tooling] How to merge multiple JSON files or inject JSON values into a template from the command line without Python or Node
Use \`jq --slurpfile vars vars.json -n '$vars\[0\] as $v \| \{name: $v.name\}'\` to load external JSON as a variable. Use \`--arg\` for string injection \(escaped\) and \`--argjson\` for raw JSON injection \(numbers/booleans/objects\).
Journey Context:
Developers write Python scripts to merge \`package.json\` templates or inject environment variables into config files. jq's variable injection is Turing-complete for config generation. \`--slurpfile\` reads the entire file as an array of JSON values \(use \`$vars\[0\]\` to access the first object\). Critical distinction: \`--arg\` treats the value as a literal string \(escapes quotes\), while \`--argjson\` parses it as JSON \(preserving numbers/booleans\). This avoids the security disaster of shell interpolation into JSON strings.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:10:56.624523+00:00— report_created — created