jq · lesson 14 of 32 · Transforming
Updating values
Assignment operators produce a modified copy of the input: = sets a value, |= updates it from its old value, += (and -=, *= …) does arithmetic, and del(path) removes.
Examples
Example 1Four kinds of change in one pipeline
Document
{ "name": "Ada", "age": 36, "tmp": true }Query
.age += 1 | .name |= ascii_upcase | .role = "lead" | del(.tmp)
.age += 1Arithmetic update: add 1 to the existing value..name |= ascii_upcaseUpdate in place: the right side receives the old value and returns the new one..role = "lead"Set a key — it is created if it didn't exist.del(.tmp)Remove a key.
Result
{"name":"ADA","age":37,"role":"lead"}Good to know
- Your input is never modified: jq builds a changed copy, which is what the result shows.