jq commands
17 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 17 shown
-
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
-
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.jsonDeep-merge two JSON files (override wins)
-
jq '[.[] | select(.value != null)]' data.jsonFilter array elements where value is not null
-
jq 'group_by(.status) | map({status: .[0].status, count: length})' data.jsonCount records grouped by status field
-
jq 'flatten(1)' nested.jsonFlatten one level of nested arrays
-
jq 'INDEX(.[]; .id)' items.jsonBuild an object keyed by the id field
-
jq -s '.[0] * .[1]' base.json override.jsonDeep merge two JSON objects (right wins on conflicts)
-
jq '.config?.database?.host // "localhost"' config.jsonOptional chaining with fallback default value
-
jq 'sort_by(.timestamp) | reverse | .[0:5]' events.jsonGet 5 most recent events sorted by timestamp descending
-
jq -r '.[] | [.id, .name, .status] | @csv' data.jsonOutput selected fields as comma-separated values
-
jq '[.[] | . + {"env": "prod"}]' items.jsonInject a new key-value pair into every array element
-
jq 'walk(if type == "string" then ascii_downcase else . end)' data.jsonRecursively lowercase all string values in a JSON document
no commands match — try a different search