Terminal GuideTerminal Guide
dasel icon

dasel

Dev Tools
macOSLinuxWindows
Go

Query and modify data in JSON, TOML, YAML, XML, CSV.

Official Website

Features

Multi-formatModify In-placeFormat ConversionSelectors

Installation

Homebrew
brew install dasel

Why use dasel?

dasel provides a unified selector syntax for querying and modifying data across JSON, YAML, TOML, XML, and CSV formats. Instead of learning different tools for each format, use one simple selector language to transform any structured data.

Multi-format Querying

Use identical selectors for JSON, YAML, TOML, XML, and CSV. Learn one syntax, use it everywhere.

In-place Modification

Edit files directly without temporary files or complex pipelines. Preserve formatting and structure.

Format Conversion

Convert between formats effortlessly. Parse YAML and output as JSON, or vice versa.

Simple Syntax

Intuitive dot-notation selectors for accessing nested values. Easy to learn and remember.

Installation

Installation
# macOS (Homebrew)
brew install dasel

# Linux (Binary)
curl -sSL https://github.com/TomWright/dasel/releases/download/v2.2.0/dasel_linux_amd64 -o dasel
chmod +x dasel
sudo mv dasel /usr/local/bin/

# Go
go install github.com/TomWright/dasel/v2/cmd/dasel@latest

# Docker
docker run --rm ghcr.io/tomwright/dasel:v2.2.0 select -f json '.name' < data.json

# Windows (Scoop)
scoop install dasel

Basic Usage

Selecting Data

Selection
# Select from JSON
dasel -f data.json -s 'name'

# Select from YAML
dasel -f config.yaml -s '.database.host'

# Select from TOML
dasel -f config.toml -s '.server.port'

# Select from XML
dasel -f data.xml -s '.root.item.name'

# Select from stdin
echo '{"name":"John"}' | dasel -s '.name'

Selector Syntax

Selectors
# Access properties
dasel -f data.json -s '.user.name'

# Array access by index
dasel -f data.json -s '.users[0].email'

# Array length
dasel -f data.json -s '.users | length'

# Access all array elements
dasel -f data.json -s '.users[]'

# Nested array access
dasel -f data.json -s '.users[1].addresses[0].zip'

Modifying Data

Modification
# Update a value
dasel -f config.json -s '.database.port' -v 5432

# Update in-place (modify file)
dasel -f config.json -s '.database.port' -v 5432 -o config.json

# Add new property
dasel -f data.json -s '.newfield' -v 'value'

# Delete a field
dasel -f data.json -s '.tempfield' -d

# Update nested value
dasel -f config.yaml -s '.server.ssl.enabled' -v true

Format Conversion

Conversion
# YAML to JSON
dasel -f config.yaml -o json

# JSON to YAML
dasel -f data.json -o yaml

# TOML to JSON
dasel -f settings.toml -o json

# XML to YAML
dasel -f data.xml -o yaml

# Convert and pretty-print
dasel -f data.json -o json --pretty

Common Use Cases

Configuration File Management

Configuration
# Update application version
dasel -f package.json -s '.version' -v '2.0.0' -o package.json

# Enable debug mode
dasel -f config.yaml -s '.logging.level' -v 'debug' -o config.yaml

# Set API endpoint
dasel -f settings.toml -s '.api.endpoint' -v 'https://api.example.com' -o settings.toml

# Update database credentials
dasel -f config.json -s '.database.user' -v 'newuser' -o config.json
dasel -f config.json -s '.database.password' -v 'newpass' -o config.json

Batch Processing

Batch Processing
# Process multiple JSON files
for file in *.json; do
  dasel -f "$file" -s '.id'
done

# Update all configs
for config in configs/*.yaml; do
  dasel -f "$config" -s '.timeout' -v 30 -o "$config"
done

# Extract IDs from multiple files
for file in data/*.json; do
  echo "File: $file"
  dasel -f "$file" -s '.user.id'
done

Data Extraction and Transformation

Extraction
# Extract specific fields
dasel -f data.json -s '.users[].email'

# Get nested values
dasel -f api-response.json -s '.data.result[].name'

# Extract array of values
dasel -f config.json -s '.services[].url'

# Combine with jq for complex transformation
dasel -f data.json -o json | jq '.[] | select(.status == "active")'

Validation and Inspection

Validation
# Check if value exists
dasel -f config.json -s '.optional.field'

# Get data type
dasel -f data.json -s '.count' -o json

# Inspect structure
dasel -f complex.xml -s '.root' -o json --pretty

# Validate JSON
dasel -f data.json -o json && echo "Valid JSON"

# Count array elements
dasel -f data.json -s '.items | length'

Working with CSV

CSV Operations
# Read CSV (convert to JSON first)
dasel -f data.csv

# Select column from CSV
dasel -f data.csv -s '.[].name'

# Filter CSV data
dasel -f data.csv -s '.[] | select(.status == "active")'

# Convert CSV to YAML
dasel -f data.csv -o yaml

# Update CSV values
dasel -f data.csv -s '.[0].name' -v 'NewName'

Advanced Features

Complex Selectors

Complex Selectors
# Multiple nested access
dasel -f data.json -s '.company.departments[0].employees[].name'

# Array filtering (using pipe)
dasel -f data.json -s '.users[] | select(.age > 21)'

# Chain operations
dasel -f data.json -s '.items[] | .price' -o json

# Get keys
dasel -f data.json -s '.config | keys'

# Get values
dasel -f data.json -s '.settings | values'

Output Formatting

Output Formatting
# Pretty-printed output
dasel -f data.json -s '.data' -o json --pretty

# Raw string output (no JSON encoding)
dasel -f data.json -s '.name' --raw

# CSV output
dasel -f data.json -s '.users[]' -o csv

# Tab-separated values
dasel -f data.json -s '.users[]' -o tsv

# Minimal output
dasel -f data.json -s '.value'

Error Handling

Error Handling
# Exit code on failure (missing selector)
dasel -f data.json -s '.nonexistent.field' || echo "Field not found"

# Default values with fallback
dasel -f data.json -s '.optional' || echo "default_value"

# Null output for missing values
dasel -f data.json -s '.missing' -o json

# Handle empty selectors
dasel -f data.json -s '.'

Pipe Operations

Piping
# Chain multiple dasel operations
dasel -f data.json -s '.users[]' -o json | dasel -s '.name'

# Filter and transform
dasel -f data.json -o json | dasel -s '.items[] | select(.price < 100)'

# Convert and extract
dasel -f config.yaml -o json | dasel -s '.database.url'

# Combine with other tools
dasel -f data.json -s '.urls[]' | xargs curl

Command Reference

OptionDescriptionExample
-f, --fileInput file pathdasel -f data.json
-s, --selectorData selector/pathdasel -s '.user.name'
-v, --valueValue to setdasel -s '.name' -v 'John'
-o, --outputOutput formatdasel -o yaml
-d, --deleteDelete selectordasel -s '.temp' -d
--prettyPretty-print outputdasel -o json --pretty
--rawRaw output (no JSON encoding)dasel -s '.name' --raw

Tips

  • Use -o flag without specifying input format—dasel auto-detects by file extension
  • For in-place editing, redirect output: dasel -f file.json -s '.x' -v 'y' -o file.json
  • Read from stdin with no -f flag: cat data.json | dasel -s '.name'
  • Unlike some tools, dasel preserves the original file structure better when modifying—ideal for config files
  • Use --raw when extracting strings to avoid JSON quote escaping
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More