Filter by field value

Select items whose status field equals Running

cat data.json | jq '.items[] | select(.status == "Running")'

tool
jq17 commands
tags
jq

More jq commands

  • cat data.json | jq '[.items[] | {name:.metadata.name, ns:.metadata.namespace}]'

    Build a new array with only the name and namespace of each item

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

    Group items by namespace and count them in each group

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

    Hide managedFields, the noisiest part of any kubectl output

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

    Raw output (-r) with one value per line, handy for scripts

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

    Deep-merge two JSON files (override wins)

all 17 jq commands