📄
Dasel
v1
v1
  • Introduction
  • Installation
    • Update
  • Use as a go package
  • Github
  • Playground
  • Usage
    • Select
    • Put
    • Put object
    • Put document
    • Delete
    • Validate
    • Flags
      • Escape HTML
      • Format
      • Multiple
      • Null
      • Merge Input Documents
    • Supported file types
  • Selectors
    • Introduction
    • Property
    • Keys and indexes
    • Index
    • Next Available Index
    • All indexes
    • Dynamic
    • Search
    • Search Optional
    • Length
    • Type
  • Notes
    • File formatting and ordering
    • Memory usage
    • Converting between formats
  • Examples
    • JQ to Dasel
    • YQ to Dasel
    • XML
    • Filter JSON API results
Powered by GitBook
On this page
  • Select a single value
  • Select a nested value
  • Select an array index
  • Append to an array of strings
  • Update a string value
  • Update an int value
  • Overwrite an object
  • Append to an array of objects
Edit on GitHub
  1. Examples

JQ to Dasel

PreviousConverting between formatsNextYQ to Dasel

Last updated 2 years ago

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

Select a single value

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

Select a nested value

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

Select an array index

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

Append to an array of strings

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

Update a string value

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

Update an int value

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

Overwrite an object

echo '{"user": {"name": "Tom", "age": 27}}' | jq '.user = {"name": "Frank", "age": 25}'
{
  "user": {
    "name": "Frank",
    "age": 25
  }
}
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"
  }
}
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

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