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.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install a6b08736-380a-11f1-9bc6-00163e2b0d79 --target codexRun after dry-run confirms the install plan.
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
jq — Lightweight Command-Line JSON Processor
jq is the essential command-line tool for processing JSON data. It lets you slice, filter, transform, and format JSON with a concise expression language — making it indispensable for working with APIs, config files, and data pipelines in the terminal.
JSON Crack — Interactive JSON, YAML, XML and CSV Visualizer
Transform structured data formats into interactive, explorable graph visualizations. Supports JSON, YAML, XML, CSV and TOML with search, filtering and export capabilities.
Serde — High-Performance Serialization Framework for Rust
The standard Rust framework for serializing and deserializing data structures efficiently and generically across formats like JSON, TOML, YAML, MessagePack, and more.
Homer — Static Server Dashboard with YAML Configuration
Homer is a dead-simple static dashboard for your server services, configured entirely through a single YAML file with no database or backend required.