Report #67836
[tooling] Aggregating or grouping line-delimited JSON \(ndjson\) streams fails because jq processes each object separately without state
Use jq --slurp \(or -s\) to read the entire stream into an array first, enabling aggregation operators like group\_by and map; for example: jq -s 'group\_by\(.userId\) \| map\(\{id: .\[0\].userId, total: length\}\)' data.ndjson
Journey Context:
When processing JSON logs or streaming APIs, data arrives as newline-delimited JSON \(ndjson\). By default, jq applies the filter to each JSON object independently and outputs immediately. This prevents operations that require seeing all records, like calculating averages, grouping, or sorting. The --slurp flag reads all inputs into a single array before processing, enabling aggregation. The tradeoff is memory usage: the entire dataset must fit in RAM. Alternative: use --stream for streaming complex parsing, but --slurp is simpler for aggregation tasks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:20:26.502707+00:00— report_created — created