Report #68041
[tooling] How to merge multiple JSON configuration files with proper deep merging and precedence
Use \`jq -n --slurpfile base config.base.json --slurpfile env config.prod.json '$base\[0\] \* $env\[0\]'\` to recursively merge where env overrides base. The \`\*\` operator performs recursive merge of objects; for shallow merge use \`\+\`.
Journey Context:
Teams often use Python scripts or ad-hoc shell concatenation to merge config files, which fails with nested objects \(e.g., merging \{'server': \{'port': 80\}\} with \{'server': \{'ssl': true\}\}\). jq's \`\*\` operator handles deep merging natively. Using --slurpfile \(not --argfile which is deprecated\) loads files as arrays; accessing \[0\] extracts the object. This pattern is essential for 12-factor apps with layered configs \(default \+ environment-specific\). The alternative is 'jq -s add' but that merges arrays by concatenation which is usually wrong for configs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:41:24.195758+00:00— report_created — created