All tools / Buying guides / JSON vs YAML: what is the difference

JSON vs YAML: what is the difference

The short answer

Use JSON when machines talk to machines, and YAML when humans write config. JSON is the de facto interchange format — fast to parse and supported natively everywhere. YAML expresses nesting through indentation, which reads and writes much better, but one misplaced space breaks the parse. The two convert losslessly in either direction.

Key differences

AspectJSONYAML
ReadabilityFair — dense with bracketsGood — close to natural language
CommentsNot supportedSupported with #
Parse speedFast, native JSON.parseSlower, needs an extra library
Language / tool supportNative on every platformNeeds a YAML package in most languages
Risk of breakingLow — structure is explicitHigh — sensitive to indentation and tabs
Typical useAPI payloads, logs, storageKubernetes / CI / Docker Compose config

JSON

JSON grew out of JavaScript object literals and is now the de facto standard for data interchange. Its structure is fully defined by brackets and commas — indentation is irrelevant — which makes machine generation and parsing extremely stable, and every browser ships JSON.parse natively. The trade-off is verbosity: no comments, and trailing commas will bite you when writing by hand.

YAML

YAML expresses hierarchy with indentation and dashes, dropping almost all brackets. It reads and writes noticeably better and supports comments, which is exactly why Kubernetes, GitHub Actions and Docker Compose all chose it. The trade-off is indentation sensitivity: a single wrong space or a stray tab fails the parse, and most languages need an extra dependency.

How to choose

Related tools

FAQ

Is YAML a superset of JSON

Very nearly, syntactically: valid JSON can usually be read by a YAML parser. The reverse is not true — YAML anchors, comments and multi-line strings have no JSON equivalent.

Which one should a config file use

It depends on who edits it. Machine-generated and machine-read: JSON. Edited daily by humans who want to leave notes: YAML.

Can they be converted into each other

Yes, and near-losslessly. YAML anchors and comments are dropped when going to JSON, but everything else maps across cleanly.