| name | yaml-reader |
| description | Read and parse YAML files using yq command-line tool. Extract values, query nested structures, filter arrays, and validate syntax. Use when working with YAML configuration files (.yaml, .yml), docker-compose files, Kubernetes manifests, Helm charts, or any YAML parsing tasks. |
YAML Reader with yq
When reading or querying YAML files, use yq instead of the Read tool or cat command.
Quick Overview
Start by listing keys to understand the file structure:
yq 'keys' config.yaml
yq '.database | keys' config.yaml
yq '.database.host' config.yaml
Basic Operations
yq '.' config.yaml
yq '.database.host' config.yaml
yq '.spec.containers[0].image' deployment.yaml
yq '.database | (.host, .port)' config.yaml
Querying Arrays
yq '.servers[0]' config.yaml
yq '.servers[]' config.yaml
yq '.servers | length' config.yaml
yq '.services[] | select(.enabled == true)' config.yaml
yq '.containers[].name' config.yaml
Output Formats
yq -o=json '.' config.yaml
yq -r '.name' config.yaml
yq -o=props '.' config.yaml
Working with Multiple Documents
yq 'select(documentIndex == 0)' multi-doc.yaml
yq '.' multi-doc.yaml
Validation
yq '.' config.yaml > /dev/null && echo "Valid YAML"
yq 'has("database")' config.yaml
Common Use Cases
Docker Compose
yq '.services | keys' docker-compose.yaml
yq '.services.web.image' docker-compose.yaml
Kubernetes
yq '.spec.template.spec.containers[].image' deployment.yaml
yq '.metadata.name' manifest.yaml
Helm
yq '.replicaCount' values.yaml