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

Select a single value

JQ
Dasel
1
echo '{"name": "Tom"}' | jq '.name'
2
"Tom"
Copied!
1
echo '{"name": "Tom"}' | dasel -p json '.name'
2
"Tom"
Copied!

Select a nested value

JQ
Dasel
1
echo '{"user": {"name": "Tom", "age": 27}}' | jq '.user.age'
2
27
Copied!
1
echo '{"user": {"name": "Tom", "age": 27}}' | dasel -p json '.user.age'
2
27
Copied!

Select an array index

JQ
Dasel
1
echo '[1, 2, 3]' | jq '.[1]'
2
2
Copied!
1
echo '[1, 2, 3]' | dasel -p json '.[1]'
2
2
Copied!

Append to an array of strings

JQ
Dasel
1
echo '["a", "b", "c"]' | jq '. += ["d"]'
2
[
3
"a",
4
"b",
5
"c",
6
"d"
7
]
Copied!
1
echo '["a", "b", "c"]' | dasel put string -p json -s '.[]' d
2
[
3
"a",
4
"b",
5
"c",
6
"d"
7
]
Copied!

Update a string value

JQ
Dasel
1
echo '["a", "b", "c"]' | jq '.[1] = "d"'
2
[
3
"a",
4
"d",
5
"c"
6
]
Copied!
1
echo '["a", "b", "c"]' | dasel put string -p json '.[1]' d
2
[
3
"a",
4
"d",
5
"c"
6
]
Copied!

Update an int value

JQ
Dasel
1
echo '[1, 2, 3]' | jq '.[1] = 5'
2
[
3
1,
4
5,
5
3
6
]
Copied!
1
echo '[1, 2, 3]' | dasel put int -p json '.[1]' 5
2
[
3
1,
4
5,
5
3
6
]
Copied!

Overwrite an object

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

Append to an array of objects

Bash
Dasel put object
Dasel put document
1
echo '{"users": [{"name": "Tom"}]}' | jq '.users += [{"name": "Frank"}]'
2
{
3
"users": [
4
{
5
"name": "Tom"
6
},
7
{
8
"name": "Frank"
9
}
10
]
11
}
Copied!
1
echo '{"users": [{"name": "Tom"}]}' | dasel put object -p json -t string '.users.[]' name=Frank
2
{
3
"users": [
4
{
5
"name": "Tom"
6
},
7
{
8
"name": "Frank"
9
}
10
]
11
}
Copied!
1
echo '{"users": [{"name": "Tom"}]}' | dasel put document -p json '.users.[]' '{"name":"Frank"}'
2
{
3
"users": [
4
{
5
"name": "Tom"
6
},
7
{
8
"name": "Frank"
9
}
10
]
11
}
Copied!
Last modified 7mo ago