Group and count by field

Count records in each status group

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

tool
jq17 commands
tags
jq

More jq commands

  • jq 'flatten(1)' nested.json

    Flatten nested arrays by one level

  • jq 'INDEX(.[]; .id)' items.json

    Build an object keyed by the id field

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

    Deep-merge two JSON files. Values from override.json win

  • jq '.config?.database?.host // "localhost"' config.json

    The ? operator avoids errors if a step is not an object, and // falls back to localhost

  • jq 'sort_by(.timestamp) | reverse | .[0:5]' events.json

    Sort by timestamp, newest first, and take the first 5

all 17 jq commands