yq
a lightweight and portable command-line YAML processor. yq
uses jq like syntax but works with yaml files as well as json. 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, all listed below.
Notice for v4.x versions prior to 4.18.1
Since 4.18.1, yq's 'eval/e' command is the default command and no longers needs to be specified.
Older versions will still need to specify 'eval/e'.
Similarly, '-' is no longer required as a filename to read from STDIN (unless reading from multiple files).
TLDR:
Prior to 4.18.1
4.18+
When merging multiple files together, eval-all/ea
is still required to tell yq
to run the expression against all the documents at once.
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
Take a look at the discussions for common questions, and cool ideas
Install
See the github page for the various ways you can install and use yq
Known Issues / Missing Features
yq
attempts to preserve comment positions and whitespace as much as possible, but it does not handle all scenarios (see https://github.com/go-yaml/yaml/tree/v3 for details)Powershell has its own...opinions on quoting yq
See tips and tricks for more common problems and solutions.
Last updated