JQ group_by + count example

Count items per group in jq by combining group_by() with length. Interactive example that counts how many records fall into each group.

The jq expression

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

To count items per group, first split the array with group_by(path), then map each group to its size with length. Here we group API calls by .route and produce an object per route whose value is the number of calls to that route.