yq: jq for YAML
yq applies jq syntax to YAML.
Syntax
yq is the YAML equivalent of jq. Where jq processes JSON, yq processes YAML; the syntax is similar; engineers familiar with jq are productive in yq quickly.
What syntax looks like:
- yq '.spec.replicas' file.yaml extracts values.: The basic operation. Same selector syntax as jq; the path navigates the YAML structure; the result is the value at the path.
- Same syntax as jq.: jq users find yq immediately familiar. The path syntax, the filters, the operations are similar; the cognitive overhead is low.
- Multi-document support.: YAML often has multiple documents in one file. yq handles them; selectors can target specific documents; the discipline scales.
- Edit in place.: yq -i edits the file in place. Configuration changes can be scripted; the file is modified directly; the workflow is fast.
- Path expressions.: Complex path expressions navigate nested structures. .spec.containers[0].image extracts the first container's image; the syntax is concise.
The syntax is fluent for jq users. The team's investment in yq pays off in YAML manipulation.
Kubernetes
yq is particularly valuable in Kubernetes workflows. Manifests are YAML; manipulation is common; yq is the right tool.
- yq edit on k8s manifests is faster than sed.: sed handles text but does not understand YAML. yq understands YAML; edits are structural; the discipline is YAML-aware.
- Used in helmfile, kustomize workflows.: Many Kubernetes tooling workflows use yq. helmfile uses it for value file manipulation; Kustomize-related scripts use it; the discipline is integrated.
- Pre-commit hooks.: Some teams use yq in pre-commit hooks. Manifests are validated, normalized, or modified before commit; the discipline catches issues early.
- CI/CD integration.: CI pipelines use yq to manipulate manifests. Image tags, environment-specific overrides, dynamic values all are yq-applied.
- Document common patterns.: The team's runbooks include common yq patterns. New engineers learn them; the discipline is shared.
Kubernetes use is the dominant case. The team's investment in yq pays off across many manifests.
Alternatives
Two main yq implementations exist. mikefarah/yq is the popular Go-based version; kislyuk/yq is the Python version that wraps jq.
- mikefarah/yq is the popular fork.: The Go-based mikefarah/yq is widely used. Many distributions package it; the team's environment likely has it; the choice is the obvious one.
- Original kislyuk/yq wraps jq.: The original Python implementation wraps jq; YAML is converted to JSON, processed by jq, converted back. The performance is slower; the syntax is identical.
- Pick mikefarah/yq for most use cases.: Most teams should use mikefarah/yq. Better performance, native YAML handling, more features. The choice is clear for most cases.
- Watch for syntax differences.: The two yq implementations have subtle syntax differences. Scripts written for one may not work on the other; the team's scripts target a specific implementation.
- Document the choice.: The team standardizes on one implementation. Documentation references the chosen one; new engineers know which to install; the discipline is consistent.
yq as jq for YAML is one of those tooling skills that pays off in YAML-heavy environments. Nova AI Ops integrates with infrastructure tooling, surfaces patterns, and complements the team's local-tool productivity.