How to Install and Use dasel in Linux to Query and Convert JSON, YAML, and TOML

Modern DevOps engineers, cloud architects, and system administrators frequently interact with configuration files formatted across different serialisation standards: JSON for API payloads, YAML for Kubernetes manifests and GitHub Actions, TOML for Rust and Python packaging, and XML for enterprise middleware. Traditionally, parsing and updating these formats required maintaining multiple specialized CLI tools such as jq, yq, xq, or custom Python one-liners. The dasel (Data Selector) utility, written in Go, provides a unified, blazing-fast command-line interface that allows you to query, mutate, and bidirectionally convert data across JSON, YAML, TOML, XML, and CSV using a single, consistent selector syntax.

Key Advantages of Using dasel

Unlike separate language-specific parsers, dasel delivers several notable workflow benefits:

  • Universal Format Support: Reads and writes JSON, YAML, TOML, XML, and CSV natively with automatic format detection based on file extensions.
  • Zero Dependencies: Compiles to a single standalone static binary with no external interpreters or runtime libraries required.
  • Bi-directional Format Conversion: Effortlessly converts a document from one standard to another in a single command (e.g. converting a TOML file into YAML).
  • Uniform Query Syntax: Uses identical dot-notation selector queries across all supported file formats, eliminating the need to learn distinct dialect conventions.

Step 1: Install dasel on Your Linux Distribution

Install dasel using your preferred packaging method or download the standalone precompiled binary:

Method A: Install via Official Precompiled Binary (All Distributions)

# Determine system architecture and download the latest release
curl -sSLf "https://github.com/TomWright/dasel/releases/latest/download/dasel_linux_amd64" -o /tmp/dasel

# Move binary to system path and apply execution permissions
sudo install -m 755 /tmp/dasel /usr/local/bin/dasel
rm /tmp/dasel

Method B: Install on Arch Linux

sudo pacman -S dasel

Method C: Install via Homebrew on Linux

brew install dasel

Verify the Installation

dasel --version

Step 2: Query Data from JSON, YAML, and TOML Files

The primary command to extract values from a configuration file is select (or dasel without subcommands, passing the -p flag to specify your file path and -s for the selector):

Querying Nested Properties

Assume you have an application configuration file named config.yaml:

server:
  host: "127.0.0.1"
  port: 8080
database:
  connections:
    max: 20
    timeout: 30s

To extract the database maximum connections value:

dasel -f config.yaml -s "database.connections.max"

Terminal output returns the raw integer value: 20.

Querying Array Elements

To query items in a list or array, use standard bracket index notation:

# Query the first element in a list
dasel -f package.json -s "keywords.[0]"

# Query all elements in a list
dasel -f package.json -s "keywords.[]"

Step 3: Modify and Update Values In-Place

Unlike jq, which requires piping output to temporary files to modify documents, dasel provides native in-place editing using the put subcommand:

Updating Existing Property Values

# Update a port number in a YAML configuration file in-place
dasel put -f config.yaml -s "server.port" -v 9000

# Update a string value in a TOML file
dasel put -f pyproject.toml -s "project.version" -v "1.4.0"

Adding New Keys and Data Types

You can specify the explicit data type of the value being written using the -t flag (supported types include string, int, bool, and json):

# Add a boolean feature flag to a JSON document
dasel put -f appsettings.json -s "features.enableTelemetry" -t bool -v false

Step 4: Convert Between Configuration Formats

A standout capability of dasel is its ability to translate data structures across serialisation formats without requiring intermediate scripts. Use standard piping or explicit read/write format arguments:

Convert TOML to YAML

# Convert Cargo.toml to a YAML file
dasel -f Cargo.toml -w yaml > Cargo.yaml

Convert JSON to TOML

# Convert package.json into pyproject-compatible TOML
dasel -f package.json -w toml > package.toml

Convert YAML to JSON in Shell Pipelines

# Stream a Kubernetes manifest directly into a JSON API payload
cat deployment.yaml | dasel -r yaml -w json | curl -X POST -d @- https://api.internal/deploy

Step 5: Delete Keys and Array Items

To prune deprecated configuration keys or remove sensitive credentials from configuration templates before committing them to version control, use the delete subcommand:

# Remove a specific debug block from a YAML file
dasel delete -f settings.yaml -s "logging.debug"

# Remove the last element in an array
dasel delete -f inventory.json -s "servers.[-1]"

Best Practices for CI/CD and Script Automation

When incorporating dasel into automated deployment pipelines, pass the --plain flag to suppress syntax highlighting and formatting decorations, ensuring clean string outputs for shell variable assignment. Additionally, use the -w plain output format when querying string scalars in bash scripts (e.g. VERSION=$(dasel -f manifest.yaml -s "version" -w plain)) to prevent accidental trailing quotes from contaminating your environment variables.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.