yq — jq for YAML, JSON, XML, TOML, and .properties
yq is the `jq` for YAML. It reads/writes YAML, JSON, XML, TOML, and properties files with jq-compatible syntax — essential for DevOps, CI pipelines, and any config-heavy workflow.
What it is
yq (Mike Farah's Go version) brings jq's query and transformation language to YAML, JSON, XML, TOML, .properties, and CSV files. If you have ever needed to patch a Kubernetes manifest, extract a value from a Helm chart, or merge configuration files in a CI pipeline, yq handles it with a familiar jq-compatible syntax.
DevOps engineers, SREs, and platform teams use yq anywhere YAML is involved -- which in the Kubernetes ecosystem means nearly everywhere. It is a single Go binary with no runtime dependencies.
How it saves time or tokens
yq replaces fragile sed/awk/grep pipelines for editing structured data. Instead of writing regex patterns that break when indentation changes, you use path expressions that understand YAML structure. The command yq '.spec.replicas = 5' deployment.yaml is safer and more readable than the equivalent sed command.
For AI workflows, yq can pre-process configuration files before feeding them to an LLM, extracting only the relevant sections to reduce prompt token count.
How to use
- Install yq:
brew install yq # macOS
sudo snap install yq # Linux
- Query a YAML file:
yq '.spec.replicas' deployment.yaml
- Update a value in place:
yq -i '.spec.replicas = 5' deployment.yaml
Example
Merging two YAML files and converting to JSON:
# Merge base config with environment overlay
yq ea '. as $item ireduce ({}; . * $item)' base.yaml prod.yaml
# Convert YAML to JSON
yq -o=json deployment.yaml
# Extract all container images from a K8s manifest
yq '.spec.template.spec.containers[].image' deployment.yaml
These one-liners replace multi-line scripts that would otherwise require Python or a custom parser.
Related on TokRepo
- DevOps Tools -- Infrastructure and deployment tools for Kubernetes workflows
- Automation Tools -- CI/CD pipeline tools that work with config management
Common pitfalls
- There are two popular tools both named yq. The Go version by Mike Farah (most popular) and the Python version by Andrey Kislyuk use different syntax. Ensure you install the Go version (
mikefarah/yq) for jq-compatible expressions. - Multi-document YAML files require the
ea(evaluate all) command instead of plaine. Without it, yq only processes the first document. - Comments are preserved by default, which is usually desirable. However, format conversion (YAML to JSON) strips comments since JSON does not support them.
Frequently Asked Questions
jq only processes JSON. yq extends the same expression syntax to YAML, XML, TOML, CSV, and properties files. If you know jq, you already know most of yq's syntax. yq can also convert between formats (YAML to JSON, XML to YAML, etc.).
Yes. Use the `-i` flag: `yq -i '.key = value' file.yaml`. This modifies the file directly without needing to redirect output. The original formatting and comments are preserved.
Yes. Use `yq ea` (evaluate all) to process all documents in a multi-document YAML file separated by `---`. You can also select specific documents by index.
Use the official Docker image: `docker run --rm -i mikefarah/yq < file.yaml`. Alternatively, download the static binary in your Dockerfile: `ADD https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 /usr/bin/yq`.
yq will error on malformed YAML, so passing a file through yq serves as a basic syntax check. For schema validation against specific structures, combine yq with tools like kubeval or CUE.
Citations (3)
- yq GitHub— yq is a jq-compatible processor for YAML, JSON, XML, TOML, and properties files
- yq Documentation— yq usage and expression syntax documentation
- jq GitHub— jq is a lightweight command-line JSON processor
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.