JQ group_by + sum example

Sum a numeric field per group in jq by combining group_by() with add. Interactive example that totals values within each group.

The jq expression

.calls | group_by(.route) | map({key: .[0].route, value: map(.callTimeMs) | add})

To total a numeric field per group, split the array with group_by(path), pull out the numbers you want with map(.field), and sum them with add. Here we group API calls by .route and, for each route, add up the .callTimeMs values to get the total time spent per route.