What are JSON and YAML?
JSON (JavaScript Object Notation) is a lightweight text format for data interchange. Introduced in the early 2000s alongside the rise of REST APIs, it became the universal language of web services — simple, strict, and machine-friendly.
YAML (YAML Ain't Markup Language) is a human-readable data serialization format designed for configuration files. It prioritizes readability: less punctuation, support for comments, and a clean indentation-based structure.
Both formats represent the same underlying data model — objects, arrays, strings, numbers, booleans, and null — but they make very different trade-offs.
Syntax comparison
The same data expressed in both formats:
{
"name": "Jane Doe",
"age": 32,
"active": true,
"roles": ["admin", "editor"],
"address": {
"city": "Paris",
"country": "France"
}
}name: Jane Doe
age: 32
active: true
roles:
- admin
- editor
address:
city: Paris
country: FranceBoth represent exactly the same data. YAML removes the quotes, braces, and commas — indentation does the structural work instead.
This site's YAML ↔ JSON Converter switches between the two blocks above instantly, in either direction.
Key differences
YAML-only features
Comments
YAML supports comments — JSON does not# Database configuration
database:
host: localhost # or use an env var
port: 5432
name: myapp_prodMulti-line strings
YAML literal block ( | ) and folded block ( > )description: |
This is a multi-line string.
Each line is preserved as-is.
Great for scripts or SQL queries.
summary: >
This text will be folded into
a single line when parsed.Anchors and aliases
YAML anchors (&) reuse values — avoids repetitiondefaults: &defaults
retries: 3
timeout: 30
production:
<<: *defaults # inherits retries and timeout
timeout: 60 # overrides just this valueWhen to use each
- Building or consuming an API — JSON is the standard
- The data is machine-generated and machine-consumed
- You need maximum tooling compatibility (every language has a fast native JSON parser)
- Strict structure matters — no implicit type coercion surprises
- Examples:
package.json,tsconfig.json, REST API responses
- Humans will read and edit the file regularly
- You need comments to document the config
- The structure is deeply nested (YAML is less cluttered)
- You're working with tools that expect it: Docker Compose, Kubernetes, GitHub Actions, Ansible
- Examples:
docker-compose.yml,.github/workflows/*.yml,values.yaml