YAML Cheat Sheet
Quick reference for YAML syntax: scalars, sequences, mappings, anchors, multi-line strings, and common patterns for config files, Docker Compose, and CI/CD.
Basic Syntax
Sequences (Lists)
Mappings (Objects)
Multi-line Strings
Anchors & Aliases
Common Patterns
Basic Syntax
| key: value | Key-value pair (space after colon required) |
| # comment | Comment (hash to end of line) |
| --- | Document start marker |
| ... | Document end marker |
| name: "hello world" | Quoted string (preserves special chars) |
| count: 42 | Integer |
| price: 9.99 | Float |
| active: true | Boolean (true/false, yes/no, on/off) |
| empty: null | Null value (null or ~) |
| date: 2026-03-06 | Date (ISO 8601) |
Sequences (Lists)
| - item1 - item2 - item3 |
Block sequence (one item per line) |
| items: [a, b, c] | Flow sequence (inline, JSON-style) |
| - name: Alice age: 30 |
Sequence of mappings |
| - - a - b |
Nested sequences |
Mappings (Objects)
| key: value | Simple mapping |
| parent: child: value |
Nested mapping (2-space indent) |
| {name: Alice, age: 30} | Flow mapping (inline, JSON-style) |
| ? complex key : value |
Complex key syntax |
Multi-line Strings
| text: | line 1 line 2 |
Literal block (preserves newlines) |
| text: > line 1 line 2 |
Folded block (joins lines with space) |
| text: |+ | Literal block, keep trailing newlines |
| text: |- | Literal block, strip final newline |
| text: >- | Folded block, strip final newline |
Anchors & Aliases
| defaults: &defaults timeout: 30 |
Define anchor with &name |
| server: <<: *defaults |
Merge anchor with <<: *name |
| other: *defaults | Reference anchor with *name |
Common Patterns
| env: - name: DB_HOST value: localhost |
Kubernetes env vars style |
| services: web: image: nginx |
Docker Compose service |
| jobs: build: runs-on: ubuntu-latest |
GitHub Actions job |
| stages: - build - test - deploy |
CI/CD pipeline stages |
| matrix: node: [16, 18, 20] |
Build matrix (GitHub Actions) |
Try It Live
Test these patterns with our free YAML ↔ JSON Converter. No signup needed.
Open YAML ↔ JSON Converter →
Step-by-Step Guide
Read Guide →