ArticleslgStudy

computer science

YAML

YAML is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand YAML rather than just read about it. In short: YAML ( YAM-əl) is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted.

YAML — main illustration
YAML — illustration

Key takeaways

  • YAML belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect YAML to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of YAML from memory before moving on to harder problems.

Reference excerpt

YAML ( YAM-əl) is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML targets many of the same communications applications as Extensible Markup Language (XML) but has a minimal syntax that intentionally differs from Standard Generalized Markup Language (SGML). It uses Python-style indentation to indicate nesting and does not require quotes around most string values (it also supports JSON style [...] and {...} mixed in the same file). Custom data types are allowed, but YAML natively encodes scalars (such as strings, integers, and floats), lists, and associative arrays (also known as maps, dictionaries or hashmaps). These data types are based on the Perl programming language, though all commonly used high-level programming languages share very similar concepts. The colon-centered syntax, used for expressing key-value pairs, is inspired by electronic mail headers as defined in RFC 822, and the document separator --- is borrowed from MIME (RFC 2046). Escape sequences are reused from C, and whitespace wrapping for multi-line strings is inspired by HTML. Lists and hashes can contain nested lists and hashes, forming a tree structure; arbitrary graphs can be represented using YAML aliases (similar to XML in SOAP). YAML is intended to be read and written in streams, a feature inspired by SAX. Support for reading and writing YAML is available for many programming languages. Some source-code editors such as Vim, Emacs, and various integrated development environments have features that make editing YAML easier, such as folding up nested structures or automatically highlighting syntax errors. The official recommended filename extension for YAML files has been .yaml since 2006. In 2024, the MIME type application/yaml has been finalized.

History and name YAML (, rhymes with camel) was first proposed by Clark Evans in 2001, who designed it together with Ingy döt Net and Oren Ben-Kiki. Originally YAML was said to mean Yet Another Markup Language, because it was released in an era that saw a proliferation of markup languages for presentation and connectivity (HTML, XML, SGML, etc.). Its initial name was intended as a tongue-in-cheek reference to the technology landscape, referencing its purpose as a markup language with the yet another construct, but it was then repurposed between December 2001 and April 2002 as YAML Ain't Markup Language, a recursive acronym, to distinguish its purpose as data-oriented rather than document markup.

Versions

Design

Syntax A cheat sheet and full specification are available at the official site. The following is a synopsis of the basic elements. YAML accepts the entire Unicode character set, except for some control characters, and may be encoded in any one of UTF-8, UTF-16 or UTF-32. (Though UTF-32 is not mandatory, it is required for a parser to have JSON compatibility.)

Whitespace indentation is used for denoting structure; however, tab characters are not allowed as part of that indentation. Comments begin with the number sign (#), can start anywhere on a line and continue until the end of the line. Comments must be separated from other tokens by whitespace characters. If # characters appear inside of a string, then they are number sign (#) literals. List members are denoted by a leading hyphen (-) with one member per line. A list can also be specified by enclosing text in square brackets ([...]) with each entry separated by a comma. An associative array entry is represented using colon space in the form key: value with one entry per line. YAML requires the colon be followed by a space so that url-style strings like http://www.wikipedia.org can be represented without needing to be enclosed in quotes. A question mark can be used in front of a key, in the form "?key: value" to allow the key to contain leading dashes, square brackets, etc., without quotes. An associative array can also be specified by text enclosed in curly braces ({...}), with keys separated from values by colon and the entries separated by commas (spaces are not required to retain compatibility with JSON). Strings (one type of scalar in YAML) are ordinarily unquoted, but may be enclosed in double-quotes ("), or single-quotes ('). Within double-quotes, special characters may be represented with C-style escape sequences starting with a backslash (\). According to the documentation the only octal escape supported is \0. Within single quotes the only supported escape sequence is a doubled single quote ('') denoting the single quote itself as in 'don''t'. Block scalars are delimited with indentation with optional modifiers to preserve (|) or fold (>) newlines. Multiple documents within a single stream are separated by three hyphens (---). Three periods (...) optionally end a document within a stream. Repeated nodes are initially denoted by an ampersand (&) and thereafter referenced with an asterisk (*). Nodes may be labeled with a type or tag using a double exclamation mark (!!) followed by a string, which can be expanded into a URI. YAML documents in a stream may be preceded by "directives" composed of a percent sign (%) followed by a name and space-delimited parameters. Two directives are defined in YAML 1.1: The %YAML directive is used for identifying the version of YAML in a given document. The %TAG directive is used as a shortcut for URI prefixes. These shortcuts may then be used in node type tags.

Basic components Conventional block format uses a hyphen+space to begin a new item in list.

Optional inline format is delimited by comma+space and enclosed in brackets (similar to JSON).

Keys are separated from values by a colon+space. Indented blocks, common in YAML data files, use indentation and new lines to separate the key/value pairs. Inline blocks, common in YAML data streams, use comma+space to separate the key/value pairs between braces.

Strings do not require quotation marks. There are two ways to write multi-line strings, one preserving newlines (using the | character) and one that folds the newlines (using the > character), both followed by a newline character.

By default, the leading indentation (of the first line) and trailing whitespace are stripped, though other behavior can be explicitly specified.

Folded text converts newlines to spaces and removes leading whitespace.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with YAML

Start with the simplest possible case. Write down what YAML claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to YAML before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about YAML ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of YAML

In research
YAML appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses YAML in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
YAML is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer-related introductions in 2001, Data serialization formats, so understanding it makes those chapters shorter.
In everyday life
Look for YAML outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “YAML” →

How to study YAML in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what YAML means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain YAML out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is YAML in simple terms?

YAML ( YAM-əl) is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted.

Why does YAML matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study YAML?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on YAML.

Tags

  • Computer-related introductions in 2001
  • Data serialization formats

Keep exploring