Skip to content
Latchkey

yq: Usage, Options & Common CI Errors

yq reads and edits YAML (and JSON/XML) the way jq handles JSON.

yq is the go-to for editing YAML manifests in pipelines. The big trap is version skew: the Go yq (mikefarah) and the Python yq are different tools with different syntax.

What it does

yq evaluates an expression against a YAML/JSON/XML document and prints or edits the result. The widely used Go implementation (mikefarah/yq v4) uses jq-style path expressions.

Common usage

Terminal
yq '.metadata.name' deploy.yaml
yq -i '.spec.replicas = 3' deploy.yaml        # edit in place
yq -o=json '.' config.yaml                     # YAML -> JSON
yq '.images[] | .tag' values.yaml
VALUE=ci yq -i '.env = strenv(VALUE)' file.yaml

Options

FlagWhat it does
-i / --inplaceEdit the file in place
-o=json|yaml|xmlSet output format
-P / --prettyPrintPretty-print output
-r / --raw-outputEmit unquoted scalars (Python yq)
eval / eval-allEvaluate one / merge multiple docs (v4)

Common errors in CI

Syntax that "works locally" but fails in CI is almost always a version mismatch: the Python yq (a jq wrapper) needs yq -r ".x" while the Go yq v4 uses yq ".x". "Error: unknown shorthand flag" usually means the other implementation is installed. Pin the binary explicitly (download mikefarah/yq) and use strenv()/env() to inject variables rather than shell interpolation.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →