drop the json

JSON vs YAML

Both are human-readable formats for structured data, and YAML is technically a superset of JSON. In practice they are used for different things, and each has sharp edges the other avoids.

Side by side

// JSON
{
  "name": "api",
  "replicas": 3,
  "ports": [80, 443],
  "env": { "DEBUG": "false" }
}

# YAML
name: api
replicas: 3
ports: [80, 443]
env:
  DEBUG: "false"

Where JSON wins

Where YAML wins

YAML pitfalls to know

The Norway problem

In YAML 1.1, country: NO is parsed as boolean false. So are yes, on, off. Version numbers like 1.10 become the float 1.1. Quote anything that must stay a string.

Indentation is syntax

Tabs are forbidden; a one-space misalignment silently moves a key to a different parent. JSON's braces make structure explicit.

Spec size

The YAML 1.2 spec is around 80 pages; implementations disagree on edge cases. Two tools reading the same file can produce different data.

Which should you use?

Use casePick
API request/responseJSON
Data files generated by codeJSON
Hand-edited config with commentsYAML (or JSONC/JSON5)
Kubernetes, GitHub Actions, docker-composeYAML (the ecosystem decided)
package.json, tsconfigJSON — the tooling expects it

Converting between them

Because YAML is a superset, any JSON document is already valid YAML. Going the other way requires a YAML parser; losing comments and anchors is expected. If your YAML tool complains about a document, paste the JSON-looking part into the validator first — a stray tab or trailing comma is the usual culprit.