📖 Guide
YAML — Complete Reference
YAML syntax reference covering scalars, collections, anchors, multi-line strings, and common patterns.
58 commands across 9 categories
ScalarsStringsCollections (Sequences & Mappings)Nested StructuresAnchors & AliasesMulti-line StringsCommentsAdvanced TypesCommon Patterns
Scalars
| Command | Description |
|---|---|
key: value | String scalar (unquoted) |
count: 42 | Integer scalar |
price: 19.99 | Float scalar |
enabled: true | Boolean (true, false, yes, no) |
value: null | Null value (null, ~, or omit value) |
date: 2024-01-15 | Date scalar (ISO 8601) |
timestamp: 2024-01-15T10:30:00Z | Timestamp with timezone |
octal: 0o755 | Octal number (YAML 1.2) |
Strings
| Command | Description |
|---|---|
name: hello world | Plain (unquoted) string |
name: "hello\nworld" | Double-quoted string (escape sequences processed) |
name: 'it''s here' | Single-quoted string (no escapes, '' for literal ') |
not_bool: "true" | Quote to force string type when value looks like bool/number |
not_null: "null" | Quote to prevent null interpretation |
colon: "key: value" | Quote strings containing special chars (:, #, etc.) |
special: "line1\nline2\ttab" | Escape sequences: \n newline, \t tab, \\ backslash |
Collections (Sequences & Mappings)
| Command | Description |
|---|---|
fruits:\n - apple\n - banana | Block sequence (list) |
fruits: [apple, banana, cherry] | Flow sequence (inline list) |
person:\n name: Alice\n age: 30 | Block mapping (dictionary) |
person: {name: Alice, age: 30} | Flow mapping (inline dictionary) |
-\n name: Alice\n age: 30 | Sequence of mappings |
matrix:\n - [1, 2, 3]\n - [4, 5, 6] | Sequence of sequences (2D array) |
? [complex, key]\n: value | Complex mapping key (using ? indicator) |
Nested Structures
| Command | Description |
|---|---|
a:\n b:\n c: deep | Deeply nested mappings (2-space indent per level) |
users:\n - name: Alice\n roles:\n - admin | Nested sequence inside sequence item |
config:\n db:\n host: localhost\n port: 5432 | Nested config structure |
servers:\n - name: web\n ports: [80, 443] | Mixed block and flow styles |
defaults: &defaults\n adapter: postgres\ndev:\n <<: *defaults\n database: dev_db | Merge key with nested override |
Anchors & Aliases
| Command | Description |
|---|---|
defaults: &defaults\n timeout: 30 | Anchor — define a reusable node with &name |
production: *defaults | Alias — reference anchored node with *name |
<<: *defaults | Merge key — merge anchored mapping into current mapping |
dev:\n <<: *defaults\n debug: true | Merge with override — local keys take precedence |
items:\n - &first Apple\n - Banana\n - *first | Anchor and alias on scalar values |
<<: [*defaults, *extras] | Merge multiple anchors (first match wins) |
Multi-line Strings
| Command | Description |
|---|---|
text: |\n Line 1\n Line 2 | Literal block — preserves newlines |
text: >\n Line 1\n Line 2 | Folded block — joins lines with spaces |
text: |+\n Line 1\n\n | Keep trailing newlines (+ chomping indicator) |
text: |-\n Line 1 | Strip final newline (- chomping indicator) |
text: >-\n Long text\n continued here | Folded and stripped — single line, no trailing newline |
text: |2\n Indented content | Explicit indentation indicator (2 spaces) |
text: >\n Paragraph 1.\n\n Paragraph 2. | Folded with blank line — preserves paragraph breaks |
Advanced Types
| Command | Description |
|---|---|
--- | Document start marker |
... | Document end marker |
---\ndoc1\n---\ndoc2 | Multiple documents in one file |
binary: !!binary aGVsbG8= | Binary data (base64 encoded) |
not_date: !!str 2024-01-15 | Explicit type tag — force string |
set: !!set\n ? item1\n ? item2 | Set type (unique values only) |
pairs: !!pairs\n - key1: val1\n - key2: val2 | Ordered pairs type |
Common Patterns
| Command | Description |
|---|---|
env:\n DATABASE_URL: postgres://... | Environment variables mapping |
services:\n web:\n image: nginx\n ports:\n - "80:80" | Docker Compose service definition |
name: my-app\nversion: 1.0.0\ndependencies:\n - name: lib\n version: ^2.0 | Package manifest pattern |
on:\n push:\n branches: [main]\njobs:\n build:\n runs-on: ubuntu-latest | GitHub Actions workflow structure |
apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: config | Kubernetes resource pattern |
spring:\n profiles:\n active: dev\n datasource:\n url: jdbc:... | Spring Boot application.yml pattern |
📖 Free, searchable command reference. Bookmark this page for quick access.
Comments
# This is a commentkey: value # inline comment# Section header\n# ==============key: "value # not a comment"# TODO: fix this later