jq Arrays and Objects/Count items by field

Build a frequency table from array objects.

Section: Grouping and Aggregation

Count items by field

bash
bash
echo '[{"status":"ok"},{"status":"fail"},{"status":"ok"}]' | jq 'group_by(.status) | map({status: .[0].status, count: length})'
Explanation

One of the most useful jq reporting patterns.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Grouping and Aggregation
Sum numeric field
Sum one field across an array of objects.
OpenIn sheetbashsame section
Average numeric field
Compute an average across objects.
OpenIn sheetbashsame section
Min and max by field
Find objects with smallest and largest values.
OpenIn sheetbashsame section
Partition items by predicate
Split one array into matching and non-matching groups.
OpenIn sheetbashsame section
Create grouped object
Group items by key and emit object buckets.
OpenIn sheetbash2 tag match
First array item
Get the first element.
OpenIn sheetbash1 tag match