yq
a lightweight and portable command-line YAML, JSON and XML processor. yq
uses jq like syntax but works with yaml files as well as json, xml, properties, csv and tsv. It doesn't yet support everything jq
does - but it does support the most common operations and functions, and more is being added continuously.
yq is written in go - so you can download a dependency free binary for your platform and you are good to go! If you prefer there are a variety of package managers that can be used as well as Docker and Podman, all listed below.
Quick Usage Guide
Read a value:
Pipe from STDIN:
Update a yaml file, inplace
Update using environment variables
Merge multiple files
Multiple updates to a yaml file
Convert JSON to YAML
See the documentation for more examples.
Take a look at the discussions for common questions, and cool ideas
Install
wget
Use wget to download, gzipped pre-compiled binaries:
For instance, VERSION=v4.2.0 and BINARY=yq_linux_amd64
Compressed via tar.gz
Plain binary
Latest version
MacOS / Linux via Homebrew:
Using Homebrew
Linux via snap:
Snap notes
yq
installs with strict confinement in snap, this means it doesn't have direct access to root files. To read root files you can:
And to write to a root file you can either use sponge:
or write to a temporary file:
Run with Docker or Podman
Oneshot use:
Note that you can run yq
in docker without network access and other privileges if you desire, namely --security-opt=no-new-privileges --cap-drop all --network none
.
Pipe in via STDIN:
You'll need to pass the -i\--interactive
flag to docker:
Run commands interactively:
It can be useful to have a bash function to avoid typing the whole docker command:
Running as root:
yq
's container image no longer runs under root (#860). If you'd like to install more things in the container image, or you're having permissions issues when attempting to read/write files you'll need to either:
Or, in your Dockerfile:
Missing timezone data
By default, the alpine image yq uses does not include timezone data. If you'd like to use the tz
operator, you'll need to include this data:
Podman with SELinux
If you are using podman with SELinux, you will need to set the shared volume flag :z
on the volume mount:
GitHub Action
See https://mikefarah.gitbook.io/yq/usage/github-action for more.
Go Install:
Last updated