yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
Go to file
2022-11-10 10:19:41 +11:00
.gitbook/assets GitBook: [#206] deep update example 2021-10-30 03:14:39 +00:00
commands Simplified yq usage 2022-01-28 12:50:13 +11:00
operators Added set path example 2022-11-10 10:18:08 +11:00
usage Added set path example 2022-11-10 10:19:41 +11:00
how-it-works.md Bumping version 2022-09-09 11:23:34 +10:00
README.md Add link to discussions on readme 2022-08-01 16:56:21 +10:00
SUMMARY.md v4.29.1 2022-10-29 18:24:11 +11:00
upgrading-from-v3.md improved v3 merge docs 2022-08-29 10:58:08 +10:00

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

cat file.yaml | yq e '.cool' -

4.18+

cat file.yaml | yq '.cool'

When merging multiple files together, eval-all/ea is still required to tell yq to run the expression again all the document at once.

Quick Usage Guide

Read a value:

yq '.a.b[0].c' file.yaml

Pipe from STDIN:

cat file.yaml | yq '.a.b[0].c'

Update a yaml file, inplace

yq -i '.a.b[0].c = "cool"' file.yaml

Update using environment variables

NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml

Merge multiple files

yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml

Multiple updates to a yaml file

yq -i '
  .a.b[0].c = "cool" |
  .x.y.z = "foobar" |
  .person.name = strenv(NAME)
' file.yaml

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

See tips and tricks for more common problems and solutions.