Merge two objects
Deep merge two JSON objects (right wins on conflicts)
jq -s '.[0] * .[1]' base.json override.json
More jq commands
-
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