Website review
This review may include AI-generated content and is not individually verified. Domain, certificate and other facts come from the observed data on this page.
What is yq?
yq is a lightweight, portable command-line processor for YAML, JSON, INI, XML, properties, CSV and TSV files. It uses jq-style syntax, so anyone familiar with jq can query and edit structured data in YAML files with much the same mental model. Because it is written in Go, you can download a dependency-free binary for your platform, or install it through package managers, Docker or Podman as listed on yq.
What you can do with it
The documented usage patterns show the core workflow:
- Read a value:
yq '.a.b[0].c' file.yamlextracts a nested field. - Pipe from standard input:
yq '.a.b[0].c' < file.yamlworks in shell pipelines. - Edit in place:
yq -i '.a.b[0].c = "cool"' file.yamlupdates a file directly. - Use environment variables:
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yamlinjects values from the shell. - Merge files: from a simple two-file
load(...) * load(...)expression to glob-based merging withyq ea.
Who it suits
yq is most useful for developers and DevOps engineers who already script against JSON with jq and now need the same control over YAML configuration—Kubernetes manifests, CI pipelines, application configs—without hand-editing indentation. A practical scenario: a release script that reads an image tag from one YAML file, writes it into a deployment manifest, and merges environment-specific overlays, all in a few commands.
Trade-offs to know
yq does not yet support everything jq does, though common operations are covered and more is being added. It also tries to preserve comments and whitespace but does not handle every scenario, so heavily commented files can shift after an in-place edit—verify the diff before committing. PowerShell users may also hit quoting quirks.
As a next step, run yq '.a.b[0].c' file.yaml on a config file you know well, then try a single -i update on a copy and inspect the diff to see how your file's formatting survives.
How do I install yq on my platform without dependencies?
Download yq's dependency-free binary for your platform from the official releases on GitHub (the project's own page points there for install options). Because yq is written in Go and shipped as a static binary, you do not need Go, Python, jq or any runtime installed—just the executable.
Practical steps
- Open the releases page on GitHub and pick the asset matching your OS and CPU architecture (for example, Linux amd64, macOS arm64, Windows amd64).
- Download the binary, then make it executable on macOS/Linux:
chmod +x ./yq_linux_amd64 sudo mv ./yq_linux_amd64 /usr/local/bin/yq - Confirm it works:
yq --version yq '.a.b[0].c' file.yaml
On Windows, rename the downloaded file to yq.exe and place it in a folder on your PATH. If you use PowerShell, note the documented caveat that PowerShell has its own quoting rules, so wrap expressions in single quotes and test carefully.
When the binary is (and isn't) the right choice
- Choose the binary for air-gapped servers, CI containers, or machines where you cannot install package managers. This is the most portable route.
- Choose a package manager instead (Homebrew, apt, Scoop, and others listed on the GitHub page) if you want automatic updates and version pinning through your existing tooling.
- Choose Docker/Podman if you want to run yq without touching the host at all—useful for reproducible pipelines.
For a quick decision: if your environment forbids installing packages, grab the binary; if it has a package manager you already maintain, use that for easier upgrades.
How can I update a YAML value in place using a shell environment variable?
Use yq's strenv() function with the in-place flag. The pattern from the yq documentation is:
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml
strenv(NAME) reads the environment variable NAME and inserts it as a string, so values like mike don't need to be quoted and escaped into the expression by hand. -i writes the result back to file.yaml instead of printing it to stdout.
Practical points
- Quote the expression. The whole yq expression is wrapped in single quotes so the shell doesn't expand
$or split it. The variable is expanded by yq, not by the shell. - Use
env()for non-strings.strenv()forces a string; if the target field should be a number or boolean, useenv(NAME)so yq parses the value as YAML. - Test before overwriting. Run the same command without
-ifirst to see the resulting document, then add-ionce the output looks right. This matters most for nested paths, where a wrong index can create or overwrite unexpected keys. - Watch PowerShell quoting. The yq page notes PowerShell has its own opinions on quoting, so Windows users may need different quote handling than the Bash example above.
A concrete scenario: a CI job needs to set an image tag in a deployment manifest from a build variable. IMAGE_TAG=1.4.2 yq -i '.spec.template.spec.containers[0].image = "app:" + strenv(IMAGE_TAG)' deploy.yaml updates only that field and leaves the rest of the file, including comments and layout, as close to the original as yq can manage.
For broader syntax and recipes, see yq.
How do I merge multiple YAML files into one with yq?
Use yq's eval-all (short form ea) mode to merge multiple YAML files into a single document. The pattern from the yq quick usage guide is:
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
This loads every matching file at once, then folds them together with the * merge operator. ea matters here: without it, yq evaluates files one at a time instead of treating them as a combined set, which is what a true merge needs.
For two specific files, the guide shows a simpler form:
yq -n 'load("file1.yaml") * load("file2.yaml")'
Choosing between the two
- Fixed, small set of files: use the
load(...) * load(...)form; it reads clearly and names each input. - A directory or glob of files: use the
ea+ireduceform so any number of files is handled without editing the command.
What to watch for
The * operator merges maps recursively, so in the glob form later files override earlier ones on conflicting keys — check your shell's glob ordering if precedence matters. yq also tries to preserve comments and whitespace, but the documentation notes it does not handle every scenario, so inspect the merged output before committing it.
Next step: pipe the result to a file (> merged.yaml) or add -i to write in place, then diff against your originals to confirm no keys were lost. Full recipes are on yq.
How does yq differ from jq when working with YAML files?
yq is designed for YAML-first work, while jq is designed for JSON. yq borrows jq's expression syntax, so much of what you already know about jq carries over, but yq reads and writes YAML natively and also handles JSON, XML, INI, properties, CSV and TSV.
The practical differences
- Input format. jq expects JSON; feeding it a YAML file normally requires converting to JSON first. yq processes YAML directly, so
yq '.a.b[0].c' file.yamlreads a nested value without a conversion step. - In-place editing. yq supports
-ito update a file directly, e.g.yq -i '.a.b[0].c = "cool"' file.yaml. With jq you would typically write to a temp file and move it back. - Environment variables. yq has
strenv(NAME)for injecting values, useful in CI scripts:NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml. - Merging files. yq can merge with
load(...)and the multiply operator, or across globs usingeato evaluate all files at once — a common task for layered YAML configs. - Format conversion. yq can convert between YAML, JSON, XML and other formats in one tool, which jq does not do.
- Coverage. yq does not implement everything jq does; the page states it supports the most common operations and functions, with more added over time. Complex jq programs may need rewriting.
- Formatting fidelity. yq tries to preserve comments and whitespace, but not in every scenario.
| Task | jq | yq |
|---|---|---|
| Read YAML value | Convert first | Native |
| Edit file in place | Temp file workflow | -i flag |
| Merge YAML files | Manual | load() / ea with globs |
| Convert formats | No | Yes |
| Full jq function set | Yes | Partial |
Whose observation this is
The page itself notes that yq "doesn't yet support everything jq does" and that comment/whitespace preservation is imperfect. That is the project's own caveat, not an independent review.
A concrete scenario
If you maintain Kubernetes manifests or CI configs in Git and want to bump an image tag across files, yq's -i and glob merging fit that workflow directly. If your data is already JSON from an API and your scripts rely on advanced jq functions, staying with jq avoids rewriting logic.
Next step: take one existing jq filter you use on JSON, convert a sample to YAML, and run it through yq to see whether the expression and output formatting behave as expected before migrating scripts. The yq quick usage guide and recipes are the place to check syntax for merges and multi-file updates.
How do I convert JSON to YAML using yq?
Use yq's -P flag to pretty-print the output as YAML:
yq -P '.' input.json > output.yaml
The -P (--prettyPrint) flag tells yq to emit YAML instead of JSON. The . expression matches the whole document, so the entire file is converted.
Common variations
- Pipe from stdin:
cat input.json | yq -P '.' - Multiple JSON files at once:
yq -P ea '.' *.json—eaevaluates all inputs together, which is useful when you want one combined output rather than separate documents. - In-place conversion: yq's
-iflag is designed for editing files of the same format, so for a format change it's usually safer to redirect to a new file (> output.yaml) and verify it before replacing the original.
What to expect
yq aims to preserve comments and whitespace where it can, but its own documentation notes it doesn't handle every scenario. JSON has no comments, so that mostly matters when you later edit the YAML with yq and want formatting kept stable. Keys and values carry over directly; yq handles the type mapping (strings, numbers, booleans, nulls, nested objects and arrays) for you.
A practical workflow
If you're migrating a config file, run the conversion to a new file, open it to check indentation and quoting, then commit it. Keeping the original JSON alongside the YAML for one release makes rollback trivial.
For more examples, including the reverse YAML-to-JSON direction and array edits, see the yq documentation.
User reviews (0)