Aggregating JSON Lines

easy
Unit 11 · Stdlib0/3 to milestone

Event logs are often stored as JSON Lines (one JSON object per line). Implement aggregate(lines, group_by, metric) returning a dict mapping each group value to {"count": n, "sum": s, "avg": a} over the numeric metric field.

Skip blank lines; lines that aren't valid JSON or lack either field are counted in a separate "_errors" key (an int) instead of crashing. Sort the result's keys (the error key last, and only present if there were errors).

#json#aggregation#files2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Aggregating JSON Lines · TechGradify