JSON vs YAML
JSON vs YAML compared — syntax, readability, comments, data types and speed, plus when to use each and free tools to convert between them.
JSON and YAML both describe structured data, and YAML is actually a superset of JSON — every JSON document is valid YAML. The difference is ergonomics: JSON uses explicit braces and brackets and is ubiquitous in APIs, while YAML uses indentation and is favoured for human-edited config files.
JSON vs YAML at a glance
| JSON | YAML | |
|---|---|---|
| Syntax | Braces {} and brackets [], quoted keys | Indentation, minimal punctuation |
| Comments | Not supported | Supported with # |
| Readability | Compact, machine-friendly | Human-friendly for config |
| Data types | Strings, numbers, bool, null, array, object | Same + anchors, references, multi-line strings |
| Parsing | Fast, everywhere | Slower, indentation-sensitive |
| Typical use | APIs, web payloads | CI/CD, Kubernetes, app config |
When to use JSON
Choose JSON for API responses and data interchange — it is faster to parse, supported everywhere, and unambiguous. If a machine reads it, JSON is usually the safer default.
When to use YAML
Choose YAML for files humans edit by hand — CI pipelines, Docker Compose, Kubernetes manifests — where comments and clean indentation matter more than parse speed.
Tools for JSON & YAML
JSON vs YAML
日付やbooleanの値はどのように変換されますか?
js-yamlはYAML 1.2規格に準拠しており、日付はISO形式の文字列に、true/falseはboolean値に変換されます。ただし"yes"/"no"は(1.2仕様に従い)文字列のまま保持されます。
複数ドキュメント形式のYAML(---区切り)はどうなりますか?
最初のドキュメントのみが変換されます。複数のドキュメントを処理したい場合は、事前に`---`で文字列を分割してください。
YAMLのanchorやaliasにも対応していますか?
はい。anchor(&)とalias(*)はパース時に解決(resolve)され、JSON側でも対応するデータが複製された形で出力されます。