Comparison
JSON vs YAML
How JSON and YAML differ in syntax, typing, and guarantees, and what that means when you convert a document between them.
JSON and YAML both describe trees of maps, sequences, and scalars, but they make different trade-offs. JSON is a small, strict grammar designed for interchange; YAML is a larger configuration language designed for human editing.
01Where they differ
| Aspect | JSON | YAML |
|---|---|---|
| Grammar | Strict and small (RFC 8259 / ECMA-404) | Larger, with anchors, aliases, tags, and multiple documents |
| Types | Object, array, string, number, boolean, null | Same core scalars plus explicit tags and dates |
| Whitespace | Insignificant | Indentation is structure |
| Comments | Not allowed | Allowed |
| Typical use | Interchange between systems | Configuration read and edited by people |
02Converting safely
JSON to YAML round-trips the same value model, including integers larger than JavaScript can represent exactly, as long as the converter preserves scalar literals and does not add anchors or tags. The reverse is not lossless for every YAML feature: anchors, aliases, tags, and complex keys have no JSON representation.
Limitations
A converter must report unsupported YAML constructs rather than approximate them, and must state which YAML features have no JSON equivalent.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format — IETF (accessed 2026-09-01)
- YAML 1.2 Specification (Revision 1.2.2) — YAML Language Development Team
Test this in your browser
The tool runs entirely in your browser; the input you use never leaves it.
About the author
Gampangin builds and maintains free, browser-based developer tools and the documentation that makes them trustworthy. The organization is accountable for every page published on this site.