Editing keys in place — without rebuilding the whole object by hand.
Example input
{ "id": 7, "fname": "Ada", "temp": "x", "age": 36 }
Add or update a field
jq '.country = "UK"' data.json # add/overwrite .country
jq '.age += 1' data.json # update in place
jq '. + { active: true }' data.json # merge in extra fields
Delete a key
jq 'del(.temp)' data.json
Delete several keys at once
jq 'del(.temp, .id)' data.json
Delete a key from every object in an array
jq 'map(del(.temp))' people.json
Rename one key
Copy to the new name, then delete the old:
jq '.firstName = .fname | del(.fname)' data.json
Output:
{ "id": 7, "temp": "x", "age": 36, "firstName": "Ada" }
Rename keys by pattern (with_entries)
with_entries exposes each {key, value} so you can rewrite keys — e.g. strip a prefix or
camelCase them:
jq 'with_entries(.key |= sub("^f"; "first_"))' data.json
Uppercase every key:
jq 'with_entries(.key |= ascii_upcase)' data.json
|= updates in place: .age |= . + 1 reads, transforms, and writes the same path. For renames,
with_entries(...) (sugar over to_entries | map(...) | from_entries) is the clean way to rewrite
many keys at once.