Group by field

Aggregate items by a field value

cat data.json | jq 'group_by(.namespace) | map({ns: .[0].namespace, count: length})'

tool
jq17 commands
tags
jq

More jq commands

  • cat data.json | jq 'del(.metadata.managedFields)'

    Remove a field from JSON output

  • cat data.json | jq -r '.items[].metadata.name'

    Raw output (-r) for scripting; one value per line

  • jq -s '.[0] * .[1]' base.json override.json

    Deep-merge two JSON files (override wins)

  • jq '[.[] | select(.value != null)]' data.json

    Filter array elements where value is not null

  • jq 'group_by(.status) | map({status: .[0].status, count: length})' data.json

    Count records grouped by status field

all 17 jq commands