YAML Explained: How It Works and When to Use It
A developer-friendly guide to understanding YAML syntax, best practices, and how to convert YAML to and from JSON.
YAML is one of the most widely used configuration languages in modern development. You’ll find it in Docker Compose files, Kubernetes manifests, GitHub Actions workflows, static site generators, and countless other tools.
Its main strengths are readability, simplicity, and being human-friendly—but YAML also has strict rules that can trip developers up.
In this guide, you’ll learn:
- What YAML is and why it exists
- YAML syntax basics
- How YAML compares to JSON
- How to convert JSON ↔ YAML
- Common mistakes and how to avoid them
What is YAML?
YAML stands for YAML Ain’t Markup Language, a recursive acronym emphasizing that YAML is not meant for markup, but for data serialization.
It is designed to be:
- Human-readable
- Easy to write and modify
- Flexible for configuration files
- Structured without excessive symbols
You’ll often encounter YAML in:
- Kubernetes (
deployment.yaml) - Docker Compose (
docker-compose.yml) - GitHub Actions (
ci.yml) - Home Assistant
- Ansible
YAML Syntax Basics
YAML uses indentation to represent structure.
Indentation matters (spaces, not tabs!), and incorrect spacing is the #1 source of errors.
Key rules:
- Use spaces, never tabs
- Indentation defines hierarchy
- Key-value pairs use
key: value - Lists start with
-
Example YAML
name: John Doe
age: 30
isDeveloper: true
languages:
- JavaScript
- Python
- Rust
address:
street: "123 Main St"
city: "New York"
YAML vs JSON
You can think of YAML as a more human-friendly JSON.
JSON
{
"name": "John",
"age": 30
}
YAML
name: John
age: 30
JSON is stricter and predictable for machines.
YAML is more flexible and pleasant for humans.
Convert JSON ↔ YAML Instantly
JSON to YAML Converter
Paste your JSON and instantly get clean, valid YAML output—perfect for config files and DevOps workflows.
Use this tool for:
- Kubernetes manifests
- CI/CD workflows
- Docker Compose files
- GitHub Actions
Common YAML Mistakes
1. Using tabs instead of spaces
YAML does not allow tabs.
2. Misaligned indentation
Consistent indentation is required for nested structures.
3. Forgetting quotation marks
Strings with special characters require quotes.
4. Accidental nesting
A single extra space may create a child node unintentionally.
5. Boolean formatting inconsistencies
YAML accepts yes/no, on/off, true/false. JSON does not.
Frequently Asked Questions
Is YAML a replacement for JSON?
No. YAML is better for configuration, while JSON is better for structured data exchange such as APIs.
Why does YAML break so easily?
Because indentation defines structure. A single extra space can change the intended meaning of the document.
Should I use quotes in YAML?
Quotes are optional unless your string includes special characters like colons, braces, or leading zeros.
How do I convert JSON to YAML?
Use an online converter like the one above, or libraries like js-yaml when working in JavaScript.