| created | "2025-12-16T00:00:00.000Z" |
| modified | "2026-05-04T00:00:00.000Z" |
| reviewed | "2025-12-16T00:00:00.000Z" |
| name | yq-yaml-processing |
| description | yq YAML processing: query, filter, transform YAML. Use when parsing configs, modifying Kubernetes manifests or GitHub Actions workflows, or transforming YAML. |
| user-invocable | false |
| allowed-tools | Bash(yq *), Read, Write, Edit, Grep, Glob |
| model | sonnet |
yq YAML Processing
Expert knowledge for processing, querying, and transforming YAML data using yq v4+, the lightweight command-line YAML processor with jq-like syntax.
When to Use This Skill
| Use this skill when... | Use another tool instead when... |
|---|
| Querying or modifying YAML files | Processing JSON only (use jq) |
| Updating Kubernetes manifests | Full Kubernetes management (use kubectl) |
| Processing GitHub Actions workflows | XML processing (use xmlstarlet) |
| Merging YAML configurations | Complex data transformations (use scripting) |
Core Expertise
YAML Operations
- Query and filter YAML with path expressions
- Transform YAML structure and shape
- Multi-document YAML support
- Convert between YAML, JSON, XML, and other formats
Configuration Management
- Modify Kubernetes manifests
- Update GitHub Actions workflows
- Process Helm values files
- Manage application configurations
Essential Commands
Basic Querying
yq '.' file.yaml
yq '.fieldName' file.yaml
yq '.spec.containers[0].name' pod.yaml
yq '.[0]' array.yaml
yq '.items[2]' data.yaml
Reading YAML
yq '.metadata.name' deployment.yaml
yq '.spec.template.spec.containers[].image' deployment.yaml
yq '.optional // "default"' file.yaml
yq 'has("fieldName")' file.yaml
Modifying YAML (In-Place)
yq -i '.metadata.name = "new-name"' file.yaml
yq -i '.spec.replicas = 3' deployment.yaml
yq -i '.metadata.labels.app = "myapp"' file.yaml
yq -i 'del(.spec.nodeSelector)' file.yaml
yq -i '.items += {"name": "new-item"}' file.yaml
yq -i '(.items[] | select(.name == "foo")).status = "active"' file.yaml
Multi-Document YAML
yq -s '.metadata.name' multi-doc.yaml
yq 'select(document_index == 0)' multi-doc.yaml
yq eval-all '.' multi-doc.yaml
yq 'select(.kind == "Deployment")' k8s-resources.yaml
yq eval-all '. as $item ireduce ({}; . * $item)' file1.yaml file2.yaml
Object Operations
yq 'keys' file.yaml
yq '{name, version}' file.yaml
yq '. * {"updated": true}' file.yaml
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' base.yaml override.yaml
yq eval-all '. as $item ireduce ({}; . *+ $item)' base.yaml override.yaml
Agentic Optimizations
| Context | Command |
|---|
| Read field | yq '.field' file.yaml |
| Update in-place | yq -i '.field = "value"' file.yaml |
| YAML to JSON | yq -o=json '.' file.yaml |
| Compact JSON | yq -o=json -I=0 '.' file.yaml |
| Filter documents | yq 'select(.kind == "Deployment")' file.yaml |
| Merge configs | yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' base.yaml override.yaml |
| Validate YAML | yq '.' file.yaml |
Quick Reference
Operators
.field - Access field
.[] - Iterate array/object
| - Pipe (chain operations)
, - Multiple outputs
// - Alternative operator (default value)
* - Merge objects (shallow)
*+ - Deep merge objects
Functions
keys, values - Object keys/values
length - Array/object/string length
select() - Filter
sort_by() - Sort
group_by() - Group
unique - Remove duplicates
has() - Check field existence
type - Get value type
add - Sum or concatenate
del() - Delete field
Flags
| Flag | Description |
|---|
-i | In-place edit |
-o | Output format (json, yaml, xml, csv, tsv, props) |
-p | Input format (json, yaml, xml) |
-I | Indent (default: 2) |
-r | Raw output (no quotes) |
-n | Null input (create from scratch) |
-s | Split multi-document YAML |
String Functions
split(), join() - String/array conversion
contains() - String/array contains
test() - Regex match
sub(), gsub() - String substitution
upcase, downcase - Case conversion
For detailed examples, advanced patterns, and best practices, see REFERENCE.md.
Resources