Report #15357
[tooling] Aggregating multiple JSON files with jq produces invalid JSON or mangles null values
Use \`jq -s '.' file\*.json\` to slurp all inputs into a single array, or for memory-efficient streaming of many files use \`jq -n '\[inputs\]' file\*.json\`. The \`-n\` \(null input\) with \`inputs\` function provides explicit control over empty file handling and avoids automatic array wrapping behavior of \`-s\`.
Journey Context:
The naive approach \`cat \*.json \| jq '.'\` concatenates JSON objects into a stream, which is invalid JSON \(multiple roots\). \`jq -s\` \(slurp\) reads the entire input stream into a large array first, then processes it. This is correct for small files but loads everything into memory. The \`inputs\` function \(used with \`-n\`\) reads the next input only when called, allowing streaming processing with \`\[inputs\]\` constructing the array lazily. This distinction matters for >GB log files. Common pitfall: \`jq -s\` adds an extra level of array nesting if you then map over it; you often need \`jq -s 'add'\` or \`jq -s '.\[\]'\` depending on desired output structure. The \`-n\` approach is also safer for empty file lists \(returns empty array \`\[\]\` vs error with \`-s\` on empty input depending on version\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:50:57.995688+00:00— report_created — created