The each function iterates through each item of an array, similar to a foreach loop.
each
The current item is accessible via the $this variable. The current index is accessible via $key.
$this
$key
The return values from each are ignored — it is useful when you want to modify values in-place.
Most commonly used with:
search
recursive descent
--root flag
--root
<array>.each(expression)
Modifying data in-place
$ echo '[1, 2, 3]' | dasel -i json 'each($this = $this + 1)' [ 2, 3, 4 ]
Uppercase all names in a file
Combined with search — update deeply nested values
This finds all objects with a status field anywhere in the document and sets them to "active".
status
"active"
Last updated 2 months ago
$ echo '["alice", "bob"]' | dasel -i json --root 'each($this = toUpper($this))' [ "ALICE", "BOB" ]
$ cat data.json | dasel -i json --root 'search(has("status")).each(status = "active")'