If you've worked with Kubernetes, GitHub Actions, or Docker Compose, you've written YAML. If you've called an API, you've received JSON. Both formats do the same basic job — they store structured data as text — but they were built for different readers, and picking the wrong one makes your life harder than it needs to be.

The short version

YAML is built for humans to read and edit by hand. JSON is built for machines to parse quickly and unambiguously. That one sentence explains almost every difference between them.

What the same data looks like in both

Here's a small config, written first in JSON:

{
  "name": "web-service",
  "port": 8080,
  "env": ["staging", "production"],
  "debug": false
}

And the same thing in YAML:

name: web-service
port: 8080
env:
  - staging
  - production
debug: false

Same data, same meaning. The YAML version has no braces, no brackets, and no trailing commas to get wrong. Indentation alone tells you what belongs to what. That's exactly why YAML feels friendlier to write by hand — and exactly why it's riskier for a machine to parse. A single misplaced space in YAML can silently change what a document means; JSON's stricter punctuation makes structure explicit, so a parser either accepts a document or rejects it outright, with far less room for silent misinterpretation.

Where YAML wins

Where JSON wins

The famous YAML gotchas

YAML's flexibility is also where it bites people. A few classics worth knowing before you get burned by them:

Converting between them

In practice, you often need both: a human edits a YAML config, but the application that consumes it wants JSON, or an API returns JSON that you want to review as readable YAML. Since YAML is a superset of most of JSON's structure, converting between the two is usually mechanical — you're not losing information for typical configs, though YAML-only features like comments and anchors don't have a JSON equivalent and get dropped in a YAML-to-JSON conversion.

A simple rule of thumb

If a human is going to open the file in a text editor and change values by hand, lean toward YAML. If a program is going to generate it, send it over a network, or parse it thousands of times a second, lean toward JSON. Most real systems end up using both, each where it fits best — and that's a perfectly reasonable outcome.

Frequently Asked Questions

Not quite. Every JSON document is technically valid YAML (YAML 1.2 is a superset of JSON), but YAML adds features JSON doesn't have, like comments, anchors and aliases (for reusing a block of config), and multi-line string syntax. So the relationship is one-directional: YAML can do everything JSON can, plus more, but that extra flexibility is also where YAML's parsing pitfalls come from.
JSON, generally by a significant margin. Its simpler, stricter grammar is cheaper to tokenize than YAML's indentation-sensitive, feature-rich syntax. This is part of why JSON dominates in performance-sensitive contexts like APIs, while YAML is more common in files that are parsed occasionally, like build configs.
No, standard JSON has no comment syntax at all. Some tools support extensions like JSON5 or JSONC (JSON with Comments) that add this, but they're not standard JSON, and a strict JSON parser will reject them.
Because those files are meant to be written and edited by humans, often frequently, and YAML is significantly less noisy to hand-edit. Interestingly, both tools also accept JSON as valid input in most cases, since JSON is valid YAML — but nobody actually writes their manifests that way by choice.