YAML with yq: Query, Edit, and Transform

High-value yq commands for reading, updating, filtering, converting, and merging YAML in local scripts and CI pipelines.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Read and query YAML with yq
Read a nested field
yq '.spec.template.spec.containers[0].image' deployment.yaml

# Print a nested value from YAML.

Read a list
yq '.features[]' config.yaml

# Print array items from a YAML path.

Filter objects in a sequence
yq '.users[] | select(.role == "admin")' users.yaml

# Select matching records from a YAML array.

Convert YAML to JSON
yq -o=json '.' config.yaml

# Transform YAML into JSON for downstream tools.

## Edit and transform YAML with yq
Set an image tag
yq -i '.spec.template.spec.containers[0].image = "repo/api:v2"' deployment.yaml

# Update a nested container image value in place.

Append to a YAML array
yq -i '.features += ["coach me"]' config.yaml

# Add a value to a sequence in place.

Delete a key
yq -i 'del(.metadata.annotations)' deployment.yaml

# Remove an unwanted field from YAML.

Merge YAML files
yq ea '. as $item ireduce ({}; . * $item )' base.yaml override.yaml

# Combine multiple YAML files into one document.

Recommended next

No recommendations yet.