Add a field to every item

Add env: prod to every array item

jq '[.[] | . + {"env": "prod"}]' items.json

tool
jq17 commands
tags
jq

More jq commands

  • jq 'walk(if type == "string" then ascii_downcase else . end)' data.json

    Convert every string value in the document to lowercase

  • cat data.json | jq '.'

    Format and colorize a JSON file

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

    Select items whose status field equals Running

  • 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

all 17 jq commands