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

JSON and YAML compared
AspectJSONYAML
GrammarStrict and small (RFC 8259 / ECMA-404)Larger, with anchors, aliases, tags, and multiple documents
TypesObject, array, string, number, boolean, nullSame core scalars plus explicit tags and dates
WhitespaceInsignificantIndentation is structure
CommentsNot allowedAllowed
Typical useInterchange between systemsConfiguration 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.

Sources

  1. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format — IETF (accessed 2026-09-01)
  2. YAML 1.2 Specification (Revision 1.2.2) — YAML Language Development Team