Bookmarks

YAML — YAML

YAML Ain’t Markup Language

A text data-serialisation format: configurations are written with indentation and “key: value” pairs, without brackets or closing tags.

Also: yml, YAML, YAML file

checked 9 Nov

All terms

YAML was begun in 2001 by Clark Evans, Ori Ben-Kiki and Ingy döt Net, who wanted a format in which data is easier to read than in XML: no angle brackets and no closing tags. The name expands to “YAML Ain’t Markup Language”: the format describes data, not a document.

What YAML looks like

Structure is set by indentation: nesting is a shift to the right, not brackets. Mappings are written as “key: value”, lists as lines starting with a hyphen, strings are usually unquoted, and comments start with a hash. One file can hold several documents, separated by a line of three hyphens.

yaml
            services:              web:                image: nginx:1.27                ports:                  - "8080:80"                environment:                  DEBUG: "false"            # this line is a comment            

Indentation and type pitfalls

The current version of the specification is 1.2.2 (October 2021). Typical mistakes come from YAML guessing the type of a value: an unquoted string may turn out to be a number or a boolean.

MistakeWhat happens
A tab in the indentationYAML allows only spaces for indentation — the file cannot be read
Different indentation among siblingsitems at one level must sit at the same depth, otherwise you get an error or a different document
yes, no, on, offread as true and false in the version 1.1 schema, plain strings in 1.2
A leading zero and colons0777 and 19:20:30 were read as numbers in 1.1 — octal and base 60; in 1.2 octal is written 0o777, and 19:20:30 is a string
The Norway problemcountry: no becomes false in parsers using the 1.1 schema, so the string is put in quotes

Where it is used

  • Docker Compose and Kubernetes — descriptions of containers, pods and cluster resources
  • Ansible — server configuration playbooks
  • CI/CD — GitHub Actions and GitLab CI pipelines, OpenAPI API descriptions
  • application settings, such as Spring profiles

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • JSONJSON

    JSON is a subset of YAML 1.2: any JSON file is also valid YAML; YAML is more often used for configuration, as it has comments, anchors and multi-line strings.

In depth in the references

where the topic is covered in detail