dasel: Query JSON, YAML, TOML and XML With One Tool
dasel reads a value from JSON, YAML, TOML, XML or CSV using a single selector syntax, so one tool replaces jq plus yq.
When a pipeline touches several config formats, dasel saves you from learning a parser per format. It autodetects the input from the file extension and lets you override read and write formats.
What it does
dasel parses a structured document and returns the node addressed by a dot/bracket selector. It detects the format from the file extension or -r/--read, so the same .user.name selector works against JSON, YAML, TOML and XML.
Common usage
# read from a file (format from extension)
dasel -f config.yaml '.database.host'
# read JSON from stdin, explicit read format
cat config.json | dasel -r json '.servers.[0].port'
# convert YAML to JSON by setting read and write formats
dasel -f config.yaml -r yaml -w json '.'Options
| Flag | What it does |
|---|---|
| -f, --file <path> | Input file (otherwise stdin) |
| -r, --read <fmt> | Force read format: json, yaml, toml, xml, csv |
| -w, --write <fmt> | Force output format |
| -c, --compact | Compact output (no extra whitespace) |
| --plain | Print scalar values without quotes |
| -m, --multiple | Select multiple nodes (with wildcards) |
In CI
Use dasel to pull one field out of a deploy manifest and feed it to a later step, e.g. IMAGE=$(dasel -f deploy.yaml -w plain ".spec.image"). Because the same selector works across formats, a job that handles both YAML and JSON manifests needs only one binary.
Common errors in CI
dasel: command not found means the binary is not installed; it is a single Go binary, install with go install github.com/tomwright/dasel/v2/cmd/dasel@latest or download the release for your arch. could not find value (exit 1) means the selector path does not exist. Note dasel v2 changed selector syntax (leading dot required, .[0] for indices); a v1 selector like user.name fails on v2, so pin the version in CI.