JSON and YAML: An Overview
JSON (JavaScript Object Notation) and YAML (YAML Ain't Markup Language) are both data serialization formats used to represent structured data as text. They serve similar purposes but have different strengths and typical use cases.
Syntax Comparison
// JSON
{
"name": "FreeUtil",
"version": "1.0",
"features": ["jwt", "base64", "regex"],
"config": {
"maxItems": 100,
"debug": false
}
}
# YAML (same data)
name: FreeUtil
version: "1.0"
features:
- jwt
- base64
- regex
config:
maxItems: 100
debug: falseKey Differences
| JSON | YAML | |
|---|---|---|
| Comments | ❌ Not supported | ✅ Yes (#) |
| Readability | Moderate | High (no brackets/quotes) |
| Strictness | Strict | Flexible (can be error-prone) |
| Multi-line strings | Awkward (\n) | Native support |
| Data types | String, number, boolean, null, array, object | All JSON types + dates, anchors, aliases |
| Parsing speed | Fast | Slower |
| Browser support | Native | Requires library |
| Common use | APIs, web | Config files, DevOps |
When to Use JSON
- REST API requests and responses
- Web browser storage (localStorage, IndexedDB)
- Configuration files that need to be parsed by browsers
- Package.json, tsconfig.json
- When performance and strict parsing matter
When to Use YAML
- Kubernetes manifests and Helm charts
- Docker Compose files
- CI/CD pipelines (GitHub Actions, GitLab CI)
- Application configuration files (where humans write/edit the config)
- Ansible playbooks
⚠️ YAML's flexibility can be a source of bugs. The "Norway problem" is famous: the two-letter country code "NO" is parsed as boolean false in YAML 1.1. Always quote strings that could be ambiguous.