YAML (YAML Ain't Markup Language) is a human-readable data serialization format designed for structure and simplicity. It is the industry standard for configuration files across tools like Docker, Kubernetes, GitHub Actions, and Ansible.
Core Syntax & Primitive Types
Key-Value Pair name: Alex Developer Space after the colon is strictly required.
Comments # Single-line comment Begins with #. Multi-line comments don't exist.
Data Types age: 28 / active: true Integers, floats, booleans, and null (~ or null) are auto-inferred.
Strings title: "System Lead" Quotes are optional unless handling special characters or numbers.
Lists & Maps
YAML structures data using indentation. Indentation must use spaces only—tabs are invalid syntax.
YAML
# Nested Mapping (Object)
database:
host: localhost
port: 5432
credentials:
user: admin
# Sequence (List/Array)
frameworks:
- React
- Vue
- Angular
# Inline Syntax (JSON-style alternative)
compact_list: [1, 2, 3]
compact_map: { x: 10, y: 20 }
Multi-Line Strings
Literal Block (|): Preserves all newlines exactly as written.
Folded Block (>): Converts single newlines into spaces, combining lines into a continuous paragraph.
YAML
literal_text: |
Line 1
Line 2 (newline preserved)
folded_text: >
This text spans multiple lines
but will render as a single paragraph.
Anchors & Aliases (DRY Configuration)
You can reuse repeated blocks of data using & to define an anchor and * to reference it:
YAML
default_config: &default_env
timeout: 30
retries: 3
production:
<<: *default_env # Merges default_config keys here
host: prod.example.com
Common Pitfalls
Tabs vs. Spaces: Using a tab character breaks the parser. Set your editor to insert spaces.
Boolean Coercion: Unquoted values like yes, no, true, false, on, off, N, or Y are automatically cast as booleans in YAML 1.1. Always quote country codes like "NO" (Norway).