Cheatsheet: YAML
Last updated 2026-09-18
Basic syntax
Scalars are simple values such as strings, numbers, booleans, and nulls.
Lists are sequences represented by a dash followed by a space.
Flow-style lists use JSON-like brackets.
Maps are key-value pairs separated by a colon and indented for nesting.
Flow-style maps use JSON-like braces.
Nested lists and maps are expressed with indentation, not braces.
Comments start with # and continue to the end of the line.
Strings and scalars
Plain strings usually do not need quotes, but quoting avoids ambiguity.
Use single quotes by doubling them inside single-quoted strings.
Literal block scalars with | preserve line breaks.
Folded block scalars with > fold most line breaks into spaces.
Chomping indicators control the final newline of block scalars.
Explicit tags can force values to strings or other types.
Reuse and documents
Anchors name a node and aliases reuse it elsewhere.
Merge keys copy mappings from an anchored map.
Multiple YAML documents in one stream are separated with ---.
Use explicit booleans and nulls for configuration values.
Quote values that look like booleans, numbers, dates, or special characters when they must remain strings.
Common gotchas
The "Norway problem": unquoted no/yes/on/off/true/false/null are parsed as booleans or null, not strings.
Indentation must use spaces only. A tab anywhere in the indentation is a syntax error.
A colon inside an unquoted plain string (e.g. a URL or ratio) can be misread as a key/value separator. Quote it.
Leading zeros and version-looking numbers are inferred as numbers unless quoted, which can strip the zero.
Duplicate keys in the same map are not an error in the spec; the last one silently wins, which hides typos.
Trailing whitespace after a colon or dash can turn a plain scalar into an unexpected empty value.
YAML in CI/CD and config files
GitHub Actions workflows combine mapping keys with sequence steps.
Docker Compose service definitions rely on nested maps and lists for ports, volumes, and environment variables.
Kubernetes manifests use --- to separate multiple resources in one file and rely on strict indentation.