Skip to main content

YAML Syntax Cheatsheet

YAML (YAML Ain't Markup Language) is a human-readable data serialization format widely used for configuration files, CI/CD pipeline definitions, and cross-language data exchange. This cheatsheet covers common patterns from basic syntax to advanced features like anchors, multiline strings, and type system.

Updated: 2026-07-17·32 commands

Overview

YAML (YAML Ain't Markup Language) is a human-readable data serialization format commonly used for configuration files. This cheatsheet covers YAML syntax, data types, multiline strings, anchors, and advanced features.

Quick Start

``yaml key: value list: - item1 - item2 map: subkey: subvalue ``

Refer to the command table below for detailed usage.

Basic Syntax(6)

CommandLevel
key: value
Basic key-value mapping
Basic
- item
List/array definition
Basic
nested mapping
Nested mapping (indentation for nesting)
Basic
list of mappings
List of mappings (each element is key-value pairs)
Basic
# comment
Comment (from # to end of line)
Basic
indentation rules
Indentation rules (2 spaces, no tabs)
Basic

Data Types(7)

CommandLevel
'single quoted'
Single-quoted string (no escape processing)
Basic
"double quoted"
Double-quoted string (escapes processed)
Basic
unquoted string
Unquoted string (simple values)
Basic
true / false
Boolean values (case-insensitive)
Basic
null / ~
Null value representations
Basic
integer / float
Integer and floating-point numbers
Basic
ISO 8601 timestamp
ISO 8601 timestamp
Intermediate

Multiline(4)

CommandLevel
|
Literal block scalar (preserves newlines)
Intermediate
>
Folded block scalar (newlines become spaces)
Intermediate
|-
Literal block with trailing newline stripped
Intermediate
|+
Literal block with all trailing newlines kept
Intermediate

Anchors(5)

CommandLevel
&-name
Define an anchor
Intermediate
*-name
Reference an anchor (alias)
Intermediate
<<
Merge key (merge anchor mapping into current)
Intermediate
nested anchors
Nested anchors and aliases
Intermediate
multiple aliases
Single anchor referenced multiple times
Intermediate

Advanced(10)

CommandLevel
GitHub Actions workflow
YAML in GitHub Actions
Intermediate
GitLab CI pipeline
YAML in GitLab CI
Intermediate
yq eval
yq read YAML value
Basic
yq eval array
yq traverse array elements
Basic
yq eval with pipe
yq piped queries
Intermediate
yq eval -i
yq in-place edit YAML file
Intermediate
yq --yaml-all
yq process all documents in multi-doc YAML
Expert
yq path expressions
yq path expressions (wildcard, recursive)
Expert
merge YAML files
Merge multiple YAML files
Expert
multi-document YAML
Multi-document YAML (separated by ---)
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.