JQ to Dasel

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

Select a single value

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

Select a nested value

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

Select an array index

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

Append to an array of strings

JQ
Dasel
JQ
echo '["a", "b", "c"]' | jq '. += ["d"]'
[
"a",
"b",
"c",
"d"
]
Dasel
echo '["a", "b", "c"]' | dasel put string -p json -s '.[]' d
[
"a",
"b",
"c",
"d"
]

Update a string value

JQ
Dasel
JQ
echo '["a", "b", "c"]' | jq '.[1] = "d"'
[
"a",
"d",
"c"
]
Dasel
echo '["a", "b", "c"]' | dasel put string -p json '.[1]' d
[
"a",
"d",
"c"
]

Update an int value

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

Overwrite an object

JQ
Dasel put object
Dasel put document
JQ
echo '{"user": {"name": "Tom", "age": 27}}' | jq '.user = {"name": "Frank", "age": 25}'
{
"user": {
"name": "Frank",
"age": 25
}
}
Dasel put object
echo '{"user": {"name": "Tom", "age": 27}}' | dasel put object -p json -t string -t int '.user' name=Frank age=25
{
"user": {
"age": 25,
"name": "Frank"
}
}
Dasel put document
echo '{"user": {"name": "Tom", "age": 27}}' | dasel put document -p json '.user' '{"name": "Frank", "age": 25}'
{
"user": {
"age": 25,
"name": "Frank"
}
}

Append to an array of objects

Bash
Dasel put object
Dasel put document
Bash
echo '{"users": [{"name": "Tom"}]}' | jq '.users += [{"name": "Frank"}]'
{
"users": [
{
"name": "Tom"
},
{
"name": "Frank"
}
]
}
Dasel put object
echo '{"users": [{"name": "Tom"}]}' | dasel put object -p json -t string '.users.[]' name=Frank
{
"users": [
{
"name": "Tom"
},
{
"name": "Frank"
}
]
}
Dasel put document
echo '{"users": [{"name": "Tom"}]}' | dasel put document -p json '.users.[]' '{"name":"Frank"}'
{
"users": [
{
"name": "Tom"
},
{
"name": "Frank"
}
]
}