Skip to content
Latchkey

yq Command Reference: Flags, Expressions & CI Examples

yq is a portable command-line YAML, JSON, and XML processor.

yq applies jq-style expressions to YAML (and JSON/XML), reading values or editing documents in place. In CI it patches manifests, bumps image tags, and reads config without a YAML parser.

Common flags and usage

  • yq '.path' file.yaml: read a value
  • -i: edit the file in place
  • -o=json / -o=yaml: set the output format
  • -r / yq '... | @text': raw, unquoted output
  • env(VAR): interpolate an environment variable
  • "file1.yaml" "file2.yaml": process multiple documents

Example

shell
yq -i '.image.tag = strenv(IMAGE_TAG)' k8s/deployment.yaml
VERSION=$(yq -r '.version' chart/Chart.yaml)

In CI

yq -i patches manifests and Helm charts in place during a release job; strenv(VAR) injects an environment value safely. The Go mikefarah yq and the Python kislyuk yq differ in syntax, so pin the one your scripts target.

Key takeaways

  • yq applies jq-style expressions to YAML, JSON, and XML.
  • -i edits files in place; strenv() injects env values.
  • Pin the Go vs Python yq variant since the syntaxes differ.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →