jq Arrays and Objects/Partition items by predicate

Split one array into matching and non-matching groups.

Section: Grouping and Aggregation

Partition items by predicate

bash
bash
echo '[{"name":"a","active":true},{"name":"b","active":false}]' | jq '{active: map(select(.active)), inactive: map(select(.active | not))}'
Explanation

Useful for dashboards and summary reports.

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
Count items by field
Build a frequency table from array objects.
OpenIn sheetbashsame section
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
First array item
Get the first element.
OpenIn sheetbash2 tag match
Last array item
Get the last element.
OpenIn sheetbash2 tag match