Three tools, one shape
Each lets you query and transform structured data with a small expression language:
jq— JSON. The original, most widely deployed.yq— YAML, with a jq-compatible syntax. By Mike Farah's go-yq (different from the older python-yq).dasel— JSON, YAML, TOML, XML, CSV in one tool with a single jq-like syntax. Newest, broadest format support.
jq — already covered
See textproc.lesson7. The jq filter language is the lingua franca; every other tool below either copies it or improves on it.
yq — YAML the same way
brew install yq
yq '.metadata.name' deployment.yaml
yq '.spec.replicas = 5' -i deployment.yaml # in-place edit
yq -o=json '.' config.yaml | jq # convert to JSONdasel — universal
brew install dasel
dasel -f config.yaml '.database.host'
dasel -f Cargo.toml '.package.version'
dasel -f data.csv '.[0].name'
dasel -f doc.xml '.root.item.name'One tool to query any structured file format you'll meet daily.
When to reach for which
- JSON only →
jq(most ubiquitous, most docs). - YAML primarily →
yq(matches jq syntax exactly, in-place edit). - Mixed formats in one script →
dasel.
Rewriting the same YAML can change its shape
An in-place edit can reserialize comments, anchors, key order, and quoting even when one value changes. Generate to stdout, inspect a diff, and know which document features the tool cannot preserve.
Identify the implementation, not only the command name
Several projects can install an executable named yq. The path and --version identify the syntax contract. Check the installed help before pasting flags or expressions from the web.