Loading...
Loading...
YAML querying, filtering, and transformation with yq command-line tool. Use when working with YAML files, parsing YAML configuration, modifying Kubernetes manifests, GitHub Actions workflows, or transforming YAML structures.
npx skill4agent add laurigates/claude-plugins yq-yaml-processing| 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) |
# Pretty-print YAML
yq '.' file.yaml
# Extract specific field
yq '.fieldName' file.yaml
# Extract nested field
yq '.spec.containers[0].name' pod.yaml
# Access array element
yq '.[0]' array.yaml
yq '.items[2]' data.yaml# Read specific field
yq '.metadata.name' deployment.yaml
# Read nested structure
yq '.spec.template.spec.containers[].image' deployment.yaml
# Read with default value
yq '.optional // "default"' file.yaml
# Check if field exists
yq 'has("fieldName")' file.yaml# Update field value
yq -i '.metadata.name = "new-name"' file.yaml
# Update nested field
yq -i '.spec.replicas = 3' deployment.yaml
# Add new field
yq -i '.metadata.labels.app = "myapp"' file.yaml
# Delete field
yq -i 'del(.spec.nodeSelector)' file.yaml
# Append to array
yq -i '.items += {"name": "new-item"}' file.yaml
# Update all matching elements
yq -i '(.items[] | select(.name == "foo")).status = "active"' file.yaml# Split multi-document YAML
yq -s '.metadata.name' multi-doc.yaml
# Select specific document (0-indexed)
yq 'select(document_index == 0)' multi-doc.yaml
# Process all documents
yq eval-all '.' multi-doc.yaml
# Filter documents
yq 'select(.kind == "Deployment")' k8s-resources.yaml
# Combine YAML files
yq eval-all '. as $item ireduce ({}; . * $item)' file1.yaml file2.yaml# Get all keys
yq 'keys' file.yaml
# Select specific fields
yq '{name, version}' file.yaml
# Merge objects
yq '. * {"updated": true}' file.yaml
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' base.yaml override.yaml
# Deep merge
yq eval-all '. as $item ireduce ({}; . *+ $item)' base.yaml override.yaml| Context | Command |
|---|---|
| Read field | |
| Update in-place | |
| YAML to JSON | |
| Compact JSON | |
| Filter documents | |
| Merge configs | |
| Validate YAML | |
.field.[]|,//**+keysvalueslengthselect()sort_by()group_by()uniquehas()typeadddel()| Flag | Description |
|---|---|
| In-place edit |
| Output format (json, yaml, xml, csv, tsv, props) |
| Input format (json, yaml, xml) |
| Indent (default: 2) |
| Raw output (no quotes) |
| Null input (create from scratch) |
| Split multi-document YAML |
split()join()contains()test()sub()gsub()upcasedowncasedocker run --rm -i mikefarah/yq '.key' <<< 'key: value'