Boneyard Tools

YAML vs JSON: when to use each

How YAML and JSON differ, where each one fits, and what changes when you convert between them.

Readability and syntax

YAML relies on indentation and minimal punctuation, which makes it pleasant to hand-edit for configuration. JSON uses explicit braces, brackets and quotes, which makes it strict and easy for machines to parse.

What converts cleanly

Mappings become objects, sequences become arrays, and scalars become strings, numbers, booleans or null. The data model is the same, so the structure carries over directly.

What you lose

JSON has no comments and no concept of anchors, so comments are removed and anchors and aliases are expanded into their resolved values during conversion.

Frequently asked questions

Is YAML a superset of JSON?

Effectively yes. Most valid JSON is also valid YAML, which is why pasting JSON into a YAML parser usually works.