C.W.K.
Stream
Lesson 05 of 08 · published

jq, yq, dasel — Structured Data

~10 min · jq, yq, dasel, json, yaml

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

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 JSON

dasel — 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.

Code

Mixed-format pipeline·bash
# Read a YAML field, transform via jq
yq -o=json '.deployments[]' k8s.yaml \
  | jq '{name: .metadata.name, replicas: .spec.replicas}'
# Patch a TOML file in place
dasel put -t string -f Cargo.toml -v '0.5.0' '.package.version'

External links

Exercise

Install yq and dasel: brew install yq dasel. Find a YAML config you have, query a field with yq '.path' file. Then convert it to JSON: yq -o=json '.' file | jq.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.