I remember the first time I saw a YAML file. I was configuring a CI/CD pipeline, and someone had written what looked like an English document that happened to contain my build instructions. No braces, no quotes (usually), no semicolons. Just... spaces and colons. It seemed almost too simple to work.
That was five years ago. Now YAML is everywhere: Kubernetes configurations, Docker Compose, GitHub Actions, Ansible playbooks, and countless configuration files across the industry. Understanding YAML isn't optional anymore—it's fundamental.
What Makes YAML Different
YAML stands for "YAML Ain't Markup Language." The recursive acronym is intentional—it's designed to be human-readable first, machine-parsable second. Unlike JSON, which is primarily a data interchange format, YAML was designed for configuration files.
The key difference is that YAML uses indentation to denote structure. No braces, no brackets, no punctuation beyond colons and hyphens. When done right, a YAML file reads almost like pseudocode.
The Indentation Rule
This is where most people mess up: YAML uses spaces for indentation, not tabs. Always spaces. Typically two spaces per level, though you can use more. But tabs? Tabs will break your file silently more often than not.
# This is correct
database:
host: localhost
port: 5432
credentials:
username: admin
password: secret123
# This will probably break
database:
host: localhost
port: 5432
Common YAML Structures
Key-Value Pairs
The most basic structure. Simple and familiar from almost every language.
name: John Doe
email: john@example.com
age: 30
Lists
Lists can be written with hyphens or inline with brackets.
# Hyphen syntax (more common)
languages:
- Python
- JavaScript
- Go
# Inline syntax
languages: [Python, JavaScript, Go]
Nested Structures
This is where YAML shines. You can nest arbitrarily deep, and it's still readable.
company:
name: Acme Corp
departments:
engineering:
lead: Sarah Chen
size: 45
marketing:
lead: Mike Johnson
size: 12
The Pitfalls
YAML's simplicity is also its curse. There are several gotchas that trip up even experienced developers.
The Tab Problem
Already mentioned, but worth repeating. Your editor might convert spaces to tabs on paste. Always verify your indentation is spaces.
The Colon Problem
Strings containing colons need quoting:
# This breaks
url: https://example.com:8080
# This works
url: "https://example.com:8080"
The Type Problem
YAML tries to infer types. "yes" becomes true, "no" becomes false, "12" becomes a number. Sometimes you want a string, not a boolean.
# YAML parses this as boolean true
verified: yes
# Force string with quotes
verified: "yes"
When to Use YAML vs JSON
Both have their place. Use JSON when you're exchanging data between systems or APIs—it's more compact and universally supported. Use YAML when you're writing configuration files that humans need to read and maintain.
I keep a YAML validator bookmarked for exactly this reason. When my Kubernetes manifests break, I want to know fast, not after kubectl apply fails.