Data formats
What is YAML?
Definition
YAML is an indentation-based text format for configuration and structured data, designed to be easier for people to read and write than JSON or XML.
Also known as: YAML Ain't Markup Language
YAML in more detail
YAML expresses the same data model as JSON — mappings, sequences and scalars — but with whitespace instead of braces, and it allows comments, multi-line strings and references between parts of the same document. That readability is why it ended up as the configuration language of Kubernetes, GitHub Actions, Docker Compose, Ansible and much of modern infrastructure. YAML 1.2 is formally a superset of JSON, so any valid JSON document is also valid YAML.
Indentation is structure, and that has consequences. Tabs are illegal for indentation — only spaces count — and a single misaligned line changes the shape of the document rather than raising an error. Because the file is often generated by a template and consumed by a machine, a mistake usually surfaces as a confusing failure much later, which is why linting YAML in CI is standard practice.
The famous trap is implicit typing. Under the older YAML 1.1 rules, which many popular parsers still follow, bare no, off and n become the boolean false, so the country code NO reads as false — the 'Norway problem'. Bare yes becomes true, 1.0 becomes a float, 08 can fail as an invalid octal, and a version number like 1.2.3 stays a string only because it has two dots. Quote anything that must remain a string.
One more edge worth knowing: anchors and aliases let a document reference itself, and a maliciously nested set of them can expand exponentially — the billion laughs attack. Load untrusted YAML with a safe loader that resolves only basic types and never constructs arbitrary objects.
YAML example
# docker-compose style
version: "3.9"
services:
web:
image: nginx:1.27
ports:
- "8080:80"
environment:
COUNTRY: "NO" # quoted, or it may parse as false
DEBUG: false # a real boolean
VERSION: "1.0" # quoted, or it becomes the number 1.0
command: >
nginx -g
'daemon off;'
defaults: &defaults # anchor
restart: unless-stopped
worker:
<<: *defaults # alias, merges the anchored mapYAML — common questions
- Is JSON valid YAML?
- Yes, under YAML 1.2, which is a strict superset of JSON. In practice it depends on your parser's conformance, but every mainstream YAML library will read a JSON document without complaint.
- Why did my YAML value become false?
- Almost certainly the Norway problem: an unquoted no, off, n or false is interpreted as a boolean by parsers following YAML 1.1 rules. Wrapping the value in quotes keeps it a string.
- Can I use tabs in YAML?
- Not for indentation — the specification forbids it, and parsers will error out. Tabs are only legal inside quoted scalar values. Configure your editor to insert spaces for .yml and .yaml files.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary