YQ to Dasel
The follow examples show a set of yq commands and the equivalent in dasel.

Select a single value

YQ
Dasel
1
echo 'name: Tom' | yq '.name'
2
"Tom"
Copied!
1
echo 'name: Tom' | dasel -p yaml '.name'
2
Tom
Copied!

Select a nested value

YQ
Dasel
1
echo 'user:
2
name: Tom
3
age: 27' | yq '.user.age'
4
27
Copied!
1
echo 'user:
2
name: Tom
3
age: 27' | dasel -p yaml '.user.age'
4
27
Copied!

Select an array index

YQ
Dasel
1
echo '- 1
2
- 2
3
- 3' | yq '.[1]'
4
2
Copied!
1
echo '- 1
2
- 2
3
- 3' | dasel -p yaml '.[1]'
4
2
Copied!

Append to an array of strings

YQ
Dasel
1
echo '- a
2
- b
3
- c' | yq --yaml-output '. += ["d"]'
4
- a
5
- b
6
- c
7
- d
Copied!
1
echo '- a
2
- b
3
- c' | dasel put string -p yaml -s '.[]' d
4
- a
5
- b
6
- c
7
- d
Copied!

Update a string value

YQ
Dasel
1
echo '- a
2
- b
3
- c' | yq --yaml-output '.[1] = "d"'
4
- a
5
- d
6
- c
Copied!
1
echo '- a
2
- b
3
- c' | dasel put string -p yaml -s '.[1]' d
4
- a
5
- d
6
- c
Copied!

Update an int value

YQ
Dasel
1
echo '- 1
2
- 2
3
- 3' | yq --yaml-output '.[1] = 5'
4
- 1
5
- 5
6
- 3
Copied!
1
echo '- 1
2
- 2
3
- 3' | dasel put int -p yaml -s '.[1]' 5
4
- 1
5
- 5
6
- 3
Copied!

Overwrite an object

YQ
Dasel put object
Dasel put document
1
echo 'user:
2
name: Tom
3
age: 27' | yq --yaml-output '.user = {"name": "Frank", "age": 25}'
4
user:
5
name: Frank
6
age: 25
Copied!
1
echo 'user:
2
name: Tom
3
age: 27' | dasel put object -p yaml -t string -t int '.user' name=Frank age=25
4
user:
5
age: 25
6
name: Frank
Copied!
1
echo 'user:
2
name: Tom
3
age: 27' | dasel put document -p yaml -d json '.user' '{"name":"Frank","age":25}'
4
user:
5
age: 25
6
name: Frank
Copied!

Append to an array of objects

YQ
Dasel put object
Dasel put document
1
echo 'users:
2
- name: Tom' | yq --yaml-output '.users += [{"name": "Frank"}]'
3
users:
4
- name: Tom
5
- name: Frank
Copied!
1
echo 'users:
2
- name: Tom' | dasel put object -p yaml -t string '.users.[]' name=Frank
3
users:
4
- name: Tom
5
- name: Frank
Copied!
1
echo 'users:
2
- name: Tom' | dasel put document -p yaml -d json '.users.[]' '{"name":"Frank"}'
3
users:
4
- name: Tom
5
- name: Frank
Copied!
Last modified 6mo ago