jq Arrays and Objects/Create grouped object

Group items by key and emit object buckets.

Section: Entries and Key-Value Maps

Create grouped object

bash
bash
echo '[{"team":"eng","name":"a"},{"team":"eng","name":"b"},{"team":"ops","name":"c"}]' | jq 'group_by(.team) | map({key: .[0].team, value: map(.name)}) | from_entries'
Explanation

Excellent for reporting and reshaping lists into keyed groups.

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 Entries and Key-Value Maps
Filter object entries by value
Remove entries below a threshold.
OpenIn sheetbashsame section
Rename keys with entries
Rename object keys during transformation.
OpenIn sheetbashsame section
Create object from array items
Index objects by a field.
OpenIn sheetbashsame section
Map object values
Transform each value while keeping keys unchanged.
OpenIn sheetbashsame section
Count items by field
Build a frequency table from array objects.
OpenIn sheetbash2 tag match
First array item
Get the first element.
OpenIn sheetbash1 tag match