Modifying data
Last updated
Use --root whenever you are modifying data and intend to save it back to a file.
This ensures you get the complete updated document rather than just the changed value.
By default, dasel outputs the result of the final selector in your query. This is convenient when you’re simply retrieving a value, but can be less helpful when you’re modifying data, since you often want to see the full document instead.
$ echo '{
"foo": {
"bar": "baz"
}
}' | dasel -i json 'foo.bar'
"baz"Here, the final selector is foo.bar, so dasel outputs its value: "baz".
$ echo '{
"foo": {
"bar": "baz"
}
}' | dasel -i json 'foo.bar = "bong"'
"bong"When updating a value, dasel still outputs the result of the final selector — in this case, the new value "bong".
To print the entire modified document, use the --root flag.
This changes the output to always return the full root node, regardless of the final selector.
Default
dasel -i json 'foo.bar = "bong"'
"bong" (final selector value)
--root
dasel -i json --root 'foo.bar = "bong"'
Full document with updated "foo.bar"
Last updated
$ echo '{
"foo": {
"bar": "baz"
}
}' | dasel -i json --root 'foo.bar = "bong"'
{
"foo": {
"bar": "bong"
}
}