YAML, Explained
iLoveConverter Team 3 min read
On this page
YAML (YAML Ain’t Markup Language) is a data serialization language designed to be read and written by humans. Since its debut in 2001, it has become the backbone of DevOps tooling — Docker Compose, Kubernetes, GitHub Actions, GitLab CI, and Ansible all rely on YAML for configuration. It is intentionally simple: no angle brackets, no closing braces, no commas. Indentation is the only structural marker.
What YAML looks like
services:
web:
image: nginx:latest
ports:
- "8080:80"
depends_on:
- db
db:
image: postgres:15
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
Compare that to the equivalent JSON — YAML is noticeably cleaner for configuration where readability matters more than raw compactness.
Technical details
| Aspect | Details |
|---|---|
| Type system | Maps, sequences, scalars (strings, numbers, booleans, null, dates) |
| Indentation | 2 or 4 spaces; tabs are forbidden |
| Comments | Yes, with # |
| Anchors & aliases | Repeatable nodes via &anchor and *alias |
| Multi-line strings | ` |
| Schema versions | YAML 1.1 and 1.2 — 1.2 aligns with JSON |
| Security risk | !! tags can load arbitrary types — use safe parsers |
YAML vs JSON vs TOML
| Feature | YAML | JSON | TOML |
|---|---|---|---|
| Human readability | Excellent | Good | Excellent |
| Comments | Yes | No | Yes |
| Native date/time | Yes | No | Yes |
| Self-referential | Yes (anchors) | No | No |
| Strictness | Flexible (many styles) | Very strict | Strict |
| Web adoption | Limited | Universal | Growing |
| Learning curve | Moderate (indentation gotchas) | Low | Low |
Conversion routes
YAML is most commonly converted to and from JSON, since the two are nearly equivalent under YAML 1.2.
- YAML to JSON — removes comments, normalizes indentation, produces web-safe JSON. Safe for config-driven APIs.
- JSON to YAML — adds comments, improves readability for DevOps teams editing configs.
- YAML to TOML — flattens deeply nested structures into section headers; useful when moving from Docker Compose to simpler tools.
- YAML to CSV — extract a list of scalars or flatten specific keys into tabular rows.
Common pitfalls
- Tabs vs spaces — YAML forbids tabs. A single tab character will break parsing. Configure your editor to show whitespace.
yes/noandon/off— in YAML 1.1 these parse as booleans. Quote them if you mean strings.- Excessive nesting — more than 3–4 levels deep becomes hard to read. Consider anchors or splitting files.
- Large files — YAML is not ideal for datasets with thousands of records. Use JSON or CSV instead.
FAQ
Is YAML better than JSON?
Neither is universally better. YAML wins for configuration files where humans edit by hand. JSON wins for APIs and machine-to-machine communication where strictness and ubiquity matter. They are close cousins — YAML 1.2 is a superset of JSON.
Why do Kubernetes and Docker use YAML?
YAML’s clean syntax, native date/time types, support for comments, and anchors that avoid repetition make it ideal for infrastructure-as-code. JSON would force every manifest to be cluttered with commas, braces, and quoted booleans.
Is YAML safe to parse from untrusted sources?
Only if you use a safe parser. YAML’s !! tags can deserialize arbitrary Python or Ruby objects, leading to remote code execution. Always use safe/safe_load equivalents in production code.
Can YAML represent everything JSON can?
Yes. YAML 1.2 is a strict superset of JSON. Every valid JSON file is also valid YAML (though some parsers pre-1.2 may reject it). The reverse is not true — YAML has comments, anchors, multi-line strings, and native dates that JSON lacks.
Try it yourself — free, right in your browser
Everything mentioned in this guide runs locally on this site: no upload, no watermark, no sign-up.
Format deep-dives: YAML (.yml.yaml) , JSON (.json) , TOML (.toml)