Add field to every element
Inject a new key-value pair into every array element
jq '[.[] | . + {"env": "prod"}]' items.json
More jq commands
-
jq 'walk(if type == "string" then ascii_downcase else . end)' data.jsonRecursively lowercase all string values in a JSON document
-
cat data.json | jq '.'Format and colorize a JSON file
-
cat data.json | jq '.items[] | select(.status == "Running")'Select objects where a field equals a value
-
cat data.json | jq '[.items[] | {name:.metadata.name, ns:.metadata.namespace}]'Project only specific fields into a new array
-
cat data.json | jq 'group_by(.namespace) | map({ns: .[0].namespace, count: length})'Aggregate items by a field value