jq Cheat Sheet/Filter array and keep array output

Return matching elements as an array.

Section: Filters and Conditions

Filter array and keep array output

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

Wrap `select()` with `map()` when you want an array back.

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 Filters and Conditions
Select objects matching condition
Filter array items based on a boolean expression.
OpenIn sheetbashsame section
Fallback default value
Use a fallback when a value is null or missing.
OpenIn sheetbashsame section
Conditional expression
Branch based on input values.
OpenIn sheetbashsame section
Update field value
Set an object field to a new value.
OpenIn sheetbashsame section
Increment numeric field
Increase a numeric value in place.
OpenIn sheetbashsame section
Delete object key
Remove a field from an object.
OpenIn sheetbashsame section