C.W.K.
Stream
Lesson 01 of 08 · published

What Is YAML, and Where You Already Use It

~10 min · yaml, history, config

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

YAML Ain't Markup Language

The recursive acronym is the joke; the design goal is real. YAML is meant to be a human-readable data serialization language. It targets the same job as JSON (data interchange, config) with less punctuation and more whitespace. Current spec: YAML 1.2.2 (2021); many tools still ship YAML 1.1 parsers.

YAML is a JSON superset

Every valid JSON document is valid YAML 1.2. The reverse is not true — YAML adds dates, multi-line strings, anchors, comments, and looser quoting rules. A YAML parser usually round-trips through JSON; a JSON parser cannot read most YAML.

Where you already use YAML

  • Kubernetes manifests — every Deployment, Service, ConfigMap is YAML.
  • Docker Composedocker-compose.yaml defines multi-container apps.
  • CI/CD — GitHub Actions, GitLab CI, CircleCI, Travis all use YAML.
  • Ansible — playbooks, inventory, roles all in YAML.
  • Static-site front matter — Jekyll, Hugo, Astro, Next MDX (the markdown track touched this).
  • Application config — Spring Boot's application.yaml, FastAPI/Pydantic settings, OpenAPI specs.
Principle: YAML's selling point is human readability. The cost is sensitivity to whitespace. The format rewards careful editing and punishes muscle-memory editing. Treat YAML like Python — indentation has meaning, and so does the lack of it.

Code

Hello, YAML·yaml
# A YAML version of the JSON we wrote earlier
name: Pippa
age: 5
loves:
  - markdown
  - json
  - yaml
  - toml
home:
  city: Seoul
  timezone: Asia/Seoul
is_assistant: true
middle_name: null
Parse YAML in three languages·bash
# Python (PyYAML — pip install pyyaml)
import yaml
data = yaml.safe_load(open('config.yaml'))

# JavaScript (js-yaml — npm install js-yaml)
import yaml from 'js-yaml';
const data = yaml.load(fs.readFileSync('config.yaml', 'utf8'));

# Bash (yq — equivalent of jq for YAML)
yq . config.yaml

External links

Exercise

Convert the JSON document from the JSON Fundamentals lesson 1 into YAML by hand (don't use a converter). Then validate with yq . file.yaml or python -c 'import yaml; print(yaml.safe_load(open("file.yaml")))'. Notice how much smaller the YAML is — that's the human-readability tax JSON pays in punctuation.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.