JSON vs YAML: what is the difference?
Advanced Topics
JSON and YAML can represent the same data, but they serve different goals. JSON is compact and ubiquitous for data interchange (APIs); YAML is indentation-based and built for human-friendly configuration files. In fact, JSON is technically a subset of YAML, so most YAML parsers can read JSON.
| Aspect | JSON | YAML |
|---|---|---|
| Structure | Braces & brackets | Indentation (whitespace) |
| Comments | Not supported | Supported (#) |
| Readability | Good | Excellent for configs |
| Best for | APIs, data exchange | Config (Docker, Kubernetes, CI) |
JSON
{ "name": "app", "ports": [80, 443] }
YAML
name: app
ports:
- 80
- 443
When to use which
- Choose JSON for API payloads and anything programs exchange, since it is universal and unambiguous.
- Choose YAML for config files humans edit often (Docker Compose, Kubernetes, GitHub Actions), where comments and readability matter.
Need to tidy up JSON first? Format or minify it in your browser, or read JSON vs XML.
Still Have Questions?
Check out our other FAQ topics or return to the JSON Copilot app