Section 1 · Data formats & why they exist

Turning real things into text a computer can read

Before we touch syntax: what problem do JSON and YAML solve? They are ways to write down structured information — a person, a product, a server's settings — as plain text that both humans and programs can read. This is called serialization.

1From an idea to text

Imagine describing a student to a computer. In your head it's obvious: a name, an age, some courses, whether they've graduated. A data format is just an agreed way to write that down:

The idea (in your head)
Student
 • name  = Aisha
 • age   = 27
 • courses = JSON, YAML
 • graduated? = no
Written as JSON
{
  "name": "Aisha",
  "age": 27,
  "courses": ["JSON", "YAML"],
  "graduated": false
}

That text can now be saved to a file, sent across the internet, or read by another program written in any language. That's the whole point.

Key word: structured A .txt note is unstructured — a program can't reliably find "the age". JSON and YAML are structured: every value has a labelled place, so code can pull out exactly age or courses[0] without guessing.

2Where you'll meet them

You're doing…The formatExample file / place
Calling a web APIJSONthe response from GET /users/42
Node.js / npm projectJSONpackage.json
Browser app state / configJSONtsconfig.json, settings.json
Running containersYAMLdocker-compose.yml
KubernetesYAMLdeployment.yaml
CI/CD pipelinesYAML.github/workflows/ci.yml
Ansible automationYAMLplaybook.yml

Rough rule of thumb: machines exchange JSON (compact, unambiguous), and humans write YAML (less punctuation, easier to hand-edit). Both describe the same kinds of data.

3JSON vs YAML at a glance

JSONYAML
Full nameJavaScript Object NotationYAML Ain't Markup Language
Born~2001, from JavaScript2001, as a config-friendly format
Structure shown by{ }, [ ], commasindentation (spaces)
Comments❌ not allowed# like this
Best atAPIs, data exchangeconfiguration humans edit
Superset factAny JSON file is also valid YAML — YAML is a superset of JSON.
Surprise fact Because YAML is a superset of JSON, you can paste JSON straight into a YAML file and it just works. We'll prove it on the converter page.

🧠Checkpoint

🧠

Quick check

1. Writing a person or object down as text a program can read is called…
Serialization = turning in-memory data into a storable/transmittable text form. JSON and YAML are serialization formats.
2. A Kubernetes deployment.yaml is written in…
DevOps config — Docker Compose, Kubernetes, GitHub Actions, Ansible — is almost always YAML.
3. Which statement is true?
YAML is a superset of JSON. And it's YAML (not JSON) that allows # comments.
🔓 You're reading a free chapter of JSON & YAML — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices