JSON vs YAML

JSON and YAML both represent the same kinds of structured data - objects, arrays, scalars - but with very different ergonomics. JSON uses braces and quotes and is unforgiving; YAML uses indentation and reads more like prose, which is why it dominates config files.

The catch is that YAML's flexibility invites subtle bugs, especially around whitespace and implicit typing. JSON's strictness is annoying to hand-write but rock-solid for machines. Most stacks use both.

JSON vs YAML at a glance
AspectJSONYAML
SyntaxBraces, brackets, quotesIndentation, minimal punctuation
CommentsNot supportedSupported with #
WhitespaceInsignificantSignificant - indentation matters
Human editingFiddlyComfortable
Best forAPIs, data interchangeConfig files, CI pipelines

When to use JSON

  • You're sending data over an API or between services.
  • You want a format every language parses identically.
  • Strictness and no ambiguity matter more than readability.

When to use YAML

  • You're writing config a human will read and edit often.
  • You want inline comments to document settings.
  • You're working in Kubernetes, GitHub Actions, or similar tooling.

Verdict: JSON vs YAML

JSON wins for data exchange between machines; YAML wins for configuration humans maintain. YAML's whitespace sensitivity and implicit typing (the famous "Norway problem" where no becomes false) can bite you, so validate it. When in doubt, author in YAML for readability and convert to JSON for processing.

Questions about JSON vs YAML

Is YAML a superset of JSON?
Effectively yes - most valid JSON is also valid YAML, so a YAML parser can read JSON. The reverse isn't true because JSON lacks comments and indentation syntax.
Why does YAML break so easily?
Indentation is significant, and unquoted values get auto-typed. A stray space or an ambiguous value like yes can change meaning. Always run it through a validator.
Which should I use for config?
YAML is more comfortable for humans thanks to comments and cleaner syntax, which is why most modern tooling defaults to it.

Tools for comparing JSON vs YAML