YAML (YAML Ain't Markup Language)
YAML is a human-friendly text format for structured data that uses indentation instead of brackets. It is a superset of JSON and the usual format for configuration files, from Kubernetes manifests and GitHub Actions workflows to Docker Compose and Ansible.
Open the JSON ↔ YAML Converter Runs in your browser
What it looks like
# A Kubernetes-style config
name: web
replicas: 3
ports:
- 80
- 443
env:
DEBUG: "false"
GREETING: |
Hello,
world
Indentation (spaces only, never tabs) shows nesting. key: value lines make a mapping, - item lines make a list, and # starts a comment. Strings usually need no quotes, and | or > start multi-line text. The same data can also be written in JSON-like flow style: ports: [80, 443].
How it relates to JSON
YAML 1.2 is a superset of JSON: every JSON document is valid YAML. YAML adds comments, anchors and aliases (&name and *name) for reusing a block, merge keys (<<) for combining mappings, custom tags such as CloudFormation’s !Ref, and several documents in one file separated by ---. None of those have a JSON equivalent, so converting YAML to JSON drops or expands them, while converting JSON to YAML loses nothing.
Pitfalls
- Unquoted values that change type. Under YAML 1.1 rules, still used by PyYAML, SnakeYAML and Ruby,
NO,yes,onandoffare booleans,0755is octal 493 and1:20is 80. This is the “Norway problem”: a list of country codes turnsNOinto false. YAML 1.2 reads them as strings or ordinary numbers, so the same file differs between tools. Quote them. - Numbers that lose digits.
3.10is the number 3.1, a classic bug in CI files that list Python versions. Quote version numbers. - Indentation errors. A mis-indented line silently moves a key into a different mapping rather than causing an error. Tabs are not allowed for indentation at all.
- Duplicate keys. The spec forbids them, but many parsers keep the last one without complaint, so a repeated key can quietly override an earlier setting.
Related terms
- JSON (JavaScript Object Notation) — JSON is a lightweight, language-independent text format for structured data made of objects, arrays, strings, numbers, booleans and null. It is specified by RFC 8259 and ECMA-404 and is the default data format of web APIs.
- Cron expression — A cron expression is a compact schedule of five space-separated fields (minute, hour, day of month, month and day of week) that tells the cron daemon, and many schedulers modeled on it, when to run a job. Different systems add fields or change the rules, so the same text can mean different things.
References
Ads on this page
Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.
Go Pro to remove them →