[jq] Group an array of objects by a property

Created on November 30, 2026

Use group_by(.team) to collect objects with the same team into one array per team. The result is an array of those groups, sorted by the grouping value. In this example, team A appears before team B.

echo '[{"name":"Taro","team":"A"},{"name":"Hanako","team":"B"},{"name":"Jiro","team":"A"}]' | jq 'group_by(.team)'

Output

[
  [
    {
      "name": "Taro",
      "team": "A"
    },
    {
      "name": "Jiro",
      "team": "A"
    }
  ],
  [
    {
      "name": "Hanako",
      "team": "B"
    }
  ]
]
jq