Introduction
YAML is a text format for structured data that uses indentation instead of brackets, so it reads like an outline. It was first proposed in 2001. The current specification is YAML 1.2.2, which defines YAML 1.2, a language in which any JSON text is also valid YAML.
These pages describe YAML 1.2.2 and say where YAML 1.1 reads a file differently; the syntax of YAML 1.0 and a table of all three versions are on YAML 1.0 and each version. One reader and one tree serve every version, and each document in a file is read as the version it declares.
YAML is the common format for configuration: Docker Compose files, Kubernetes
manifests, GitHub Actions workflows, OpenAPI descriptions and Ansible playbooks are all
YAML. Files use either .yaml or .yml.
Structure
A YAML file has no header or signature. It is Unicode text, normally UTF-8, holding a stream of documents. Each document holds one node, and every node is one of three kinds:
- a mapping:
key: valueentries, with keys and values that can be any node - a sequence: an ordered list, written with
-entries - a scalar: a single value, written in one of five styles
…Byte order mark optionaloptional…Directives%YAML 1.2and%TAGlinesoptional…Directives end---optional…Content one node, in block or flow stylevaries…Document end...optional…More documents the same parts againany number
%YAML 1.2
---
# Block style, with comments
title: Example # a plain scalar
ports: [80, 443] # a flow sequence
owner: &owner # an anchor on a mapping
name: "Ada Lovelace" # a double-quoted scalar
active: true
backup_owner: *owner # an alias to the anchor
notes: | # a literal block scalar
Line one.
Line two.
...
Indentation uses spaces, never tabs. Comments start with #. Keys and
values are separated by a colon and a space.
The language
- Documents and directives – the stream, the
---and...markers,%YAMLand%TAG - Block style – indentation, block sequences and mappings, compact forms, explicit keys
- Flow style – collections in brackets, flow keys, the relation to JSON
- Scalars – plain and quoted styles, escapes and line folding
- Block scalars and chomping – literal and folded text, chomping and the indentation indicator
- Anchors and aliases – reuse of nodes, merge keys, recursion and expansion attacks
- Tags and schemas – tag handles, the failsafe, JSON and core schemas, the 1.1 type repository
- Encodings and characters – UTF-8, UTF-16 and UTF-32, detection, line breaks and tabs
- YAML 1.1 and 1.2 – the versions and how the same file can read differently
- Errors and pitfalls – the syntax errors a reader reports, what is only a note, and values like
NOand010that change meaning - YAML 1.0 and each version – the syntax of 1.0, and a table of what 1.0, 1.1 and 1.2 write differently
- Reading YAML in the explorer – the tree, the Data tab (values resolved, merge keys expanded), tag checks, repeated keys and the version rules
Common uses
A YAML file does not say what it is for. A program recognises it from its name or from its top-level keys, for example:
| Use | Usual keys or file name |
|---|---|
| GitHub Actions workflow | on, jobs |
| Docker Compose file | services |
| Kubernetes manifest | apiVersion, kind |
| OpenAPI description | openapi, paths |
| Ansible playbook | A sequence of plays with hosts and tasks |
| GitLab CI configuration | .gitlab-ci.yml, stages |
| Travis CI configuration | .travis.yml |
| Helm chart | Chart.yaml |
| MkDocs configuration | mkdocs.yml, site_name |
| Dart and Flutter package | pubspec.yaml |
| clang tools | .clang-format, .clang-tidy and .clangd, which have no .yaml extension and are YAML all the same |
The file viewer on this site reads any .yaml or .yml file, the
three clang names above, and an extensionless file that starts with %YAML
or a --- line. It names the use when the name or the top-level keys
show it, and otherwise says “general”.
Not described
Known, not yet covered
- Viewer: the file is read whole into memory (a byte per byte for UTF-8), and the node table and the Data tab’s counts live in memory as well. There is no limit of the viewer’s own on size, nesting depth or number of nodes, but a file too big for memory is reported as such, and is not read in windows. Documents are not split off and read one at a time.
- Viewer: the colouring uses one colour for a whole quoted string, so escapes inside it, the indicators
- ? :and the flow brackets are not coloured separately. This is cosmetic.
Unknown
- Reference: the value forms (booleans, numbers, timestamps) of the YAML 1.0 release of January 2004. The Internet Archive holds the type repository as it stood on 10 January 2003 and again from December 2004; nothing in between survives. The viewer reads a 1.0 document with the 2003 forms, and also accepts
yandnas booleans because example 4.27 of the 1.0 specification does. See Value forms.
What the extensions of particular programs mean (!include, language tags such
as !!python/object) and the schema of a YAML-based format such as Kubernetes
or Docker Compose are decided by the program that reads the file or by that format, so
they are not listed here. The viewer names a use from the file name and the top-level keys.
Links
Software
- Visual Studio Code – free code editor with YAML highlighting and schema checks (Windows, macOS, Linux)
- Notepad++ – free text editor with YAML highlighting (Windows)
- Sublime Text – text editor with YAML highlighting (Windows, macOS, Linux)
- yq – command-line tool that queries and edits YAML (Windows, macOS, Linux)
Developers
Reference
- YAML Ain’t Markup Language version 1.2.2 – the YAML specification