YAML (YAML Ain't Markup Language) is a human-friendly data serialization format. It is a superset of JSON — all valid JSON is valid YAML. YAML uses indentation for structure (no braces or brackets needed). Used widely in Kubernetes, Ansible, Docker Compose, GitHub Actions, and CI/CD pipelines.
| Item | Syntax / Value | Description |
|---|---|---|
| --- | --- (document start marker) | Start of YAML document — required for multi-doc files |
| ... | ... (document end marker) | End of YAML document |
| # comment | # This is a comment | Hash starts a comment — inline or full line |
| string | name: Alice Smith | Unquoted string — most common |
| quoted string | name: 'Alice Smith' or "Alice" | Single quotes: literal. Double: escape sequences |
| integer | age: 30 | Decimal integer |
| float | gpa: 3.95 | Floating point number |
| scientific | distance: 1.5e10 | Scientific notation |
| boolean | active: true / false | true/false (also yes/no, on/off in YAML 1.1) |
| null | notes: null / notes: ~ | Null value |
| date | created: 2026-06-25 | ISO 8601 date — auto-parsed as date object |
| datetime | updated: 2026-06-25T12:00:00Z | ISO 8601 datetime |
| mapping (object) | name: Alice age: 30 | Key-value pairs — the YAML object |
| nested mapping | address: city: LA state: CA | Indented nesting |
| sequence (array) | - Python - Go - Rust | Block sequence with - |
| inline sequence | langs: [Python, Go, Rust] | Flow sequence — JSON-style |
| inline mapping | addr: {city: LA, state: CA} | Flow mapping — JSON-style |
| multiline literal | | notes: | Line 1 Line 2 | Preserve newlines exactly |
| multiline folded > | desc: > Long line continues | Fold newlines into spaces |
| anchor & | defaults: &def timeout: 30 | Define reusable anchor |
| alias * | prod: <<: *def | Reference anchor (merge key) |
| merge key << | <<: *defaults | Merge all keys from anchor |
| explicit type | !!str 42 | Force value type |
| multi-document | --- doc1 --- doc2 | Multiple documents in one file |
| key with spaces | 'my key': value | Quote keys with special chars |
| key with colon | 'url: value': text | Must quote keys containing colon-space |
---
# YAML Complete Syntax Reference
# MyWebUniversity.com — Chapter 34
# ── Scalars ──────────────────────────────────────────────────
name: Alice Smith # unquoted string
title: "Senior Developer" # double-quoted (allows \n etc.)
description: 'It''s great' # single-quoted ('' = literal ')
age: 30 # integer
gpa: 3.95 # float
salary: 95_000 # underscore separator (readable)
active: true # boolean
retired: false
notes: null # null
alias_null: ~ # null (alternative)
created: 2026-06-25 # date
updated: 2026-06-25T08:00:00Z # datetime (UTC)
hex: 0xFF # hexadecimal integer
octal: 0o77 # octal
binary: 0b1010 # binary
scientific: 1.5e10 # scientific notation
# ── Multiline strings ─────────────────────────────────────────
bio: |
Alice is a senior developer at MyWebUniversity.
She specializes in Python and Go.
Newlines are preserved exactly.
summary: >
This text spans multiple lines
but newlines are folded into spaces.
Use for long prose paragraphs.
trimmed: |-
No trailing newline (- modifier)
# ── Sequences (arrays) ───────────────────────────────────────
languages:
- Python
- Go
- JavaScript
- Rust
inline_langs: [Python, Go, Rust] # flow style
nested_list:
- name: Alice
score: 95
- name: Bob
score: 87
# ── Mappings (objects) ───────────────────────────────────────
address:
street: "123 Learn Ave"
city: Techville
state: CA
zip: "90210" # quote to prevent int parsing
country: US
inline_addr: {city: LA, state: CA} # flow style
# ── Anchors and aliases ──────────────────────────────────────
defaults: &defaults
timeout: 30
retries: 3
debug: false
log_level: info
development:
<<: *defaults # merge all keys from defaults
debug: true # override specific key
log_level: debug
production:
<<: *defaults
timeout: 60
replicas: 3
# ── Nested complex structure ──────────────────────────────────
courses:
- id: CS101
title: Introduction to Python
credits: 3
grade: A
tags: [beginner, python, free]
metadata:
created: 2024-01-15
updated: 2026-06-01
published: true
- id: CS201
title: "JavaScript & Node.js" # & requires quoting
credits: 3
grade: A-
tags: [intermediate, javascript, nodejs]
metadata:
created: 2024-06-01
updated: 2026-06-15
published: true