YAML Multi-Document Streams/Read the first YAML document

Query the first document in a stream.

Section: Select and inspect documents

Read the first YAML document

bash
bash
yq 'select(documentIndex == 0)' stack.yaml
Explanation

Helpful when a file contains multiple resources and you only need one.

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 Select and inspect documents
Select Kubernetes documents by kind
Filter documents in a manifest stream.
OpenIn sheetbashsame section
Render Helm templates to YAML
Generate YAML output for inspection before deployment.
OpenIn sheetbashsame section
Split YAML documents into separate files
Write each YAML document to its own output file.
OpenIn sheetbash2 tag match
Two YAML documents in one file
Use `---` to separate resources or configs.
OpenIn sheetyaml1 tag match
Explicit document end marker
Use `...` to mark the end of a document when needed.
OpenIn sheetyaml1 tag match
Apply a multi-document manifest
Send several Kubernetes resources in one file.
OpenIn sheetbash1 tag match