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)
  1. .age += 1 Arithmetic update: add 1 to the existing value.
  2. .name |= ascii_upcase Update in place: the right side receives the old value and returns the new one.
  3. .role = "lead" Set a key — it is created if it didn't exist.
  4. del(.tmp) Remove a key.

Result

{"name":"ADA","age":37,"role":"lead"}

Try it in the playground

Good to know

  • Your input is never modified: jq builds a changed copy, which is what the result shows.

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.