YAML Cheatsheet¶
Quick reference for YAML syntax.
Basic Structures¶
Scalars¶
# Plain (unquoted)
title: Hello World
# Single quoted (literal, no escaping)
message: 'It''s a nice day'
# Double quoted (allows escaping)
path: "C:\\Windows\\System32"
# Multi-line literal (preserves newlines)
poem: |
Roses are red
Violets are blue
YAML is great
And so are you
# Multi-line folded (joins lines)
description: >
This is a long paragraph
that will be folded into
a single line with spaces.
Collections¶
Anchors & Aliases¶
# Define anchor with &
defaults: &defaults
timeout: 30
retries: 3
log_level: info
# Reference with *
production:
<<: *defaults
host: prod.example.com
staging:
<<: *defaults
host: staging.example.com
log_level: debug # Override
Documents¶
Comments¶
# Full line comment
name: value # Inline comment
# Comments can go anywhere
person:
# name: old_value # Commented out
name: new_value
Tags¶
# Explicit type tags
number: !!int 42
text: !!str 42
binary: !!binary SGVsbG8gV29ybGQ=
# Custom tags
date: !date 2025-12-10
config: !include config.yaml
Common Patterns¶
Tips & Gotchas¶
Indentation
- Use spaces only, not tabs
- Be consistent with indentation (usually 2 or 4 spaces)
- Indentation determines structure
Quotes
- Usually optional for simple strings
- Required for: strings starting with special chars, reserved words (yes, no, true, false), numbers as strings
- Example:
version: "2"notversion: 2
Reserved Words
These are interpreted as booleans/null unless quoted:
Reserved:yes, no, true, false, on, off, null, ~ Timestamps
YAML 1.1 auto-converts timestamp-like strings:
More Resources¶
- FAQ - Frequently asked questions
- Glossary - YAML terminology
- YAML Specification - Official spec