Article·
JSON vs YAML: Choosing the Right Format
A practical comparison of JSON and YAML for configuration files, APIs, and data serialization.
JSON
Strict superset of JavaScript object syntax. Every value must be quoted strings, numbers, booleans, null, arrays, or objects. No comments.
Strengths: universal support, fast parsing, unambiguous, great for APIs.
YAML
A superset of JSON with human-friendly syntax. Supports comments, multi-line strings, anchors, and aliases.
# YAML supports comments
server:
host: localhost
port: 8080
tags: [api, v2]
Strengths: readable config files, less punctuation noise.
When to Use Each
| Use case | Format |
|---|---|
| REST API responses | JSON |
| CI/CD config (GitHub Actions, etc.) | YAML |
| Package manifests | JSON |
| Kubernetes manifests | YAML |
| Inter-service messaging | JSON |
Gotchas in YAML
no,yes,on,offparse as booleans in YAML 1.1- Indentation matters — tabs are not allowed
- Norway problem: country code
NOparses asfalse
Convert between the two instantly with the JSON ↔ YAML Converter.