Extract specific fields

Project only specific fields into a new array

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

tool
jq17 commands
tags
jq

More jq commands

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

    Aggregate items by a field value

  • 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

all 17 jq commands