YAML with yq: Query, Edit, and Transform/Filter objects in a sequence

Select matching records from a YAML array.

Section: Read and query YAML with yq

Filter objects in a sequence

bash
bash
yq '.users[] | select(.role == "admin")' users.yaml
Explanation

A practical pattern when using YAML as config or fixture data.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Read and query YAML with yq
Read a nested field
Print a nested value from YAML.
OpenIn sheetbashsame section
Read a list
Print array items from a YAML path.
OpenIn sheetbashsame section
Convert YAML to JSON
Transform YAML into JSON for downstream tools.
OpenIn sheetbashsame section
Set an image tag
Update a nested container image value in place.
OpenIn sheetbash2 tag match
Append to a YAML array
Add a value to a sequence in place.
OpenIn sheetbash2 tag match
Delete a key
Remove an unwanted field from YAML.
OpenIn sheetbash2 tag match