Copyright © 2001 Brian Ingerson, Clark Evans & Oren Ben-Kiki, all rights reserved. This document may be freely copied provided that it is not modified.

YAML Ain't Markup Language, abbreviated YAML, is a human-readable data serialization format and processing model. This text describes the class of data objects called YAML document streams and partially describes the behavior of computer programs that process them.

YAML document streams encode into a serialized form the native data constructs of modern scripting languages. Strings, arrays, hashes, and other user-defined data types are supported. A YAML document stream consists of a sequence of characters, some of which are considered part of the document's content, and others which are used to indicate structure within the information stream.

A YAML processor is a software module that is used to manipulate YAML information. A processor may perform multiple functions, such as parsing a YAML serialization into a series of events, loading these events into a native language representation, dumping a native representation into a series of events, and emitting these events into a serialized form. It is assumed that a YAML processor does its work on behalf of another module, called an application. This specification describes the required behavior of a YAML processor. It describes how a YAML processor must read or write YAML document streams and the information structures it must provide to or obtain from the application.

The design goals for YAML are:

  1. YAML documents are very readable by humans.

  2. YAML interacts well with scripting languages.

  3. YAML uses host languages' native data structures.

  4. YAML has a consistent information model.

  5. YAML enables stream-based processing.

  6. YAML is expressive and extensible.

  7. YAML is easy to implement.

YAML was designed with experience gained from the construction and deployment of Brian Ingerson's Perl module Data::Denter. YAML has also enjoyed much markup language critique from SML-DEV list participants and builds upon the experiences with the Minimal XML and Common XML specifications.

YAML integrates and builds upon structures and concepts described by C, Java, Perl, Python, RFC0822 (MAIL), RFC1866 (HTML), RFC2045 (MIME), RFC2396 (URI), SAX, SOAP and XML.

YAML's core type system is based on the serialization requirements of Perl. YAML directly supports both scalar values (string, integer) and collections (array, hash). Support for common types enables programmers to use their language's native data constructs for YAML manipulation, instead of requiring a special document object model (DOM).

Like XML's SOAP, the YAML serialization supports native graph structures through a rich alias mechanism. Also like SOAP, YAML provides for application-defined types. This allows YAML to serialize rich data structures required for modern distributed computing.

YAML provides unique global type names using a namespace mechanism inspired by Java's DNS based package naming convention and XML's URI based namespaces.

YAML's block scoping is similar to Python's. In YAML, the extent of a node is indicated by its column. YAML's block leaf leverages this by enabling formatted text to be cleanly mixed within an aggregate structure without troublesome escaping. Further, YAML's block indenting provides for easy inspection of the document's structure.

Motivated by HTML's end-of-line normalization, YAML's folded leaf introduces a unique method of handling whitespace. In YAML, single line breaks may be folded into a single space. This technique allows for paragraphs to be word-wrapped without affecting the canonical form of the content.

YAML's escaped leaf uses familar C-style escape sequences. This enables ASCII representation of non-printable or 8-bit (ISO 8859-1) characters such as '\x3B'. 16-bit Unicode and 32-bit (ISO/IEC 10646) characters are supported with escape sequences such as '\u003B' and '\U0000003B'.

The syntax of YAML was motivated by Internet Mail (RFC0822). Further, YAML borrows the document separator from MIME (RFC2045). YAML's top level production is a stream of independent documents; ideal for distributed processing systems.

YAML was designed to have an incremental interface which includes both a pull-style input stream and a push-style (SAX-like) output stream interfaces. Together this enables YAML to support the processing of large documents, such as a transaction log, or continuous streams, such as a feed from a production machine.

There are many differences between YAML and the eXtensible Markup Language (XML). XML was designed to be backwards compatible with Standard Generalized Markup Language (SGML) and thus had many design constraints placed on it that YAML does not share. Also XML, inheriting SGML's legacy, is designed to support structured documents, where YAML is more closely targeted at messaging and native data structures. Where XML is a pioneer in many domains, YAML is the result of many lessons from the XML community.

The YAML and XML information models are starkly different. In XML, the primary construct is an attributed tree, where each element has an ordered, named list of children and an unordered mapping of names to strings. In YAML, the primary graph constructs are keyed collections (natively stored as a hash or array) and scalar values (string, integer, floating point). This difference is critical since YAML's model is directly supported by native data structures in most modern programming languages, where XML's model requires mapping conventions, or an alternative programming component (e.g. a document object model).

The terminology used to describe YAML is defined in the body of this specification. The terms defined in the following list are used in building those definitions and in describing the actions of a YAML processor:

may

Conformant YAML streams and processors are permitted to but need not behave as described.

should

Conformant YAML texts and processors are encouraged to behave as described, but may do otherwise if a warning mesage is provided to the user and any deviant behavior requires concious effort to enable. (i.e. a non-default setting)

must

Conformant YAML texts and processors are required to behave as described, otherwise they are in error.

error

A violation of the rules of this specification; results are undefined. Conforming software must detect and report an error and may recover from it.

Conceptually, a YAML system may be understood as three interacting states: a serialization format, an event stream, and a native binding. Translating YAML information between these states are four processing components: a parser, a loader, a dumper and an emitter. The parser extracts structured information from the input stream. The loader converts this information into the appropriate native structures.

[serialization  format]

-->

[event  stream]

-->

[native  binding]

 

(parser)

 

(loader)

 

 

 

 

 

 

[serialization  format]

<--

[event  stream]

<--

[native  binding]

 

(emitter)

 

(dumper)

 

For each one of the states above, there is a corresponding information model. The graph model covers the native binding, the tree model covers the event stream, and the syntax model covers the serialization format. Type information is moved between these states using the the type family and string format constructs.

graph model

The graph model abstracts data structures of common programming languages. Nodes in the graph include collections or scalars. A collection is modeled as a function from one set of nodes to another. Scalars are nodes having a string representation. Both kinds of nodes have a type family.

tree model

The tree model flattens the graph structure into a hierarchy of branches, leaves and alias nodes. A branch represents the first occurrence of a collection, a leaf represents the first occurrence of a given scalar, and an alias is a surrogate used for subsequent occurrences of either collections or scalars. In this model, collections are realized as an ordered set of node pairs, called a branch.

syntax model

The syntax model enhances the tree model with comments, leaf styles and other serialization specific details. Serializations must comply with the syntax productions given in the following section.

A processor need not expose the event stream (tree model) and may translate directly between a serialization and its native binding. However, such a direct translation should take place so that the native binding is constructed only from information available in the graph model. In particular, information particular to the the tree model (alias anchors and pair ordering) and syntax-specific information (comments and styles) should not be used in the construction of a native binding. Exceptions to this guideline include editors which must operate on a direct image of the serialization format.

There are several core concepts shared by each information model, primarily relating to type information and how it is communicated between the serialization format and a native binding.

The type family mechanism provides an abstraction of data types which is portable across various languages and platforms. Each native binding may have zero or more native concrete types or class constructs which correspond to a given type family.

name

A URI used as a globally unique identifier for the type family. YAML does not require that this URI point to anything in particular. However, where possible, it is considered good practice to have the URI point to some human-readable document providing information about the type data family.

definition

A description of the particular category of information, independent of language and platform.

formats

Each type family used for scalar nodes has associated string formats. These formats can be separated into two groups, implicit formats and explicit formats. In addition, one of the formats is designated to be the type family's canonical string format.

Type families used for collection nodes do not have any associated string formats.

implicit formats

A set of zero or more string formats used for implicit typing. Each format may only be used in a single type family for this purpose.

explicit formats

A set of zero or more string formats used for explicit typing. It is possible for two type families to share the same explicit format, though this practice is discouraged.

canonical format

In addition to the above, each scalar type family must provide a canonical string format. This must be one of the implicit or explicit formats, or a subset of one of these formats. The canonical format must provide exactly one unique string representation for each possible value of the scalar.

In general, there may be more than one native type which corresponds to a YAML type family. In the Python language, for example, the integer family may be bound to either the plain integer capable of holding 32 bits, or the long integer with unlimited size. In ambiguous situations like this, the loader should choose between the alternative based on the requirements of the native binding.

In other cases, a binding may not have an appropriate native construct for a given type family. This may be addressed with a generic YAML construct to act as a place-holder so that the data value and the type family may round-trip. Alternatively, with warning to the user, a value may be cast to a different, perhaps less specific family. Otherwise, when a native binding for a particular value is not possible, the parser must treat it as an error.

It may be possible to write a string value of a leaf in more than one way. For example, an integer value of 255 can also be written in hex as 0xFF. This distinction is covered by the concept of a string format.

name

Each string format has a name used for for explicit typing and for general identification. This name must comply with the format production, and must be unique within the type families it applies to.

definition

A description of the format as it applies to particular data values.

regexp

Regular expressions may be provided to allow implicit typing using the string format, or to enable the YAML processor to validate that a given value is indeed compliant with the string format.

As noted above, each scalar type family has exactly one canonical string format, although more than one string format may apply. For example, the scientific format is the canonical format for floating point numbers, but such numbers are typically written using the fixed format.

The graph model abstracts data structures of common programming languages. The model is a graph of collection and scalar values, where each node in the graph is provided with type information. The model provides an intermediate interface between the parser/emitter, which can be shared by multiple native languages, and the loader/dumper, which is specific to a particular binding. The model also provides a concrete representation for language-independent storage, simple structural queries, and graph transformations.

In the graph model, YAML is viewed as a directed graph of typed nodes. Nodes that can reference other nodes are collections and nodes with a string representation are scalars. The graph model also requires node identity and a mechanism to determine if two different nodes have the same content.

A graph node is the building block of YAML structures. In the serialization, they are represented by indented blocks. Within a native binding they represent application-specific objects. In the graph model, a node is tagged with a type family and can either be a collection or a scalar.

kind

A node may be one of two kinds, a collection or a scalar.

type family

Each node is associated with a type family. For native data, this association may be implicit, based on the native data type of the node.

In most programming languages, there are two manners in which variables can be equivalent. The first is by reference, where the two variables refer to the same memory address. We call this equivalence relation "identity".

The second form of equivalence occurs when two nodes are different (have a different memory addresses), but share the same content (same binary layout). We call this second form of equivalence "equality". It follows that when two nodes are identical they are also equal.

A node set is an unordered association of zero or more graph nodes. A node may participate in many node sets without restriction, allowing for a graph structure. Node sets may not contain duplicates, that is, a node with a particular identity may only appear once. The primary purpose of the node set is to provide a basis for the definition of a collection. A native binding usually exposes node sets through a mechanism to enumerate the keys of a hash or dictionary.

A collection is a graph node which represents sequences such as lists or arrays, or mappings such as hashes or dictionaries. In the graph model, sequences are treated uniformly as mappings with integer keys. There are three collection rules. First, a set of keys may not contain two nodes that are equal. Second, each key is associated with exactly one value. Finally, each value is associated with at least one key. Note that this does not prevent a value from being associated with more than one key.

domain

A domain is a node set restricted such that no two nodes in the set may be equal. Nodes which are members of the domain are often called "keys".

range

A range is node set without restrictions. Nodes which are members of the range are often called "values".

function

A function is a rule of correspondence from the domain onto the range such that there is a unique value in the range assigned to every key in the domain, and every value in the range is assigned to at least one key.

YAML requires the mapping collection type family, which covers associative containers such as the Perl hash or Python dictionary. When the domain is a series of sequential integers starting with zero, the preferred type family is the sequence which corresponds to a Perl array or a Python list.

Node equality determines when two given nodes have the same content. When two nodes are equivalent under this equivalence relation, they are said to be "equal". Equality is defined between scalar nodes and between collection nodes, as described below.

scalar equality

Two scalars are equal if and only if they have the same type family and their canonical string representations have exactly the same series of Unicode characters.

collection equality

Equality of a collection is defined recursively. Two collections are equal if and only if they have the same type family and for each key in the domain of one, there is a corresponding key in the domain of the other such that both keys are equal and their corresponding values are equal; here corresponding value refers to the unique node in the range of the collection assigned to the key by the collection's function.

A YAML text (file or stream) is a series of disjoint graphs, each with a root node.

stream

A series of zero or more document root nodes.

document

A top level graph node that is disjoint from all other root document nodes.

The term disjoint means that for any two nodes x and y, there does not exist a third node z that is reachable from both x and y. For any node x, x is reachable from y if and only if either x and y are identical, or y is a collection and there exists a node z in the domain or the range of y such that x is reachable from z.

To allow for YAML to be communicated as a series of events, an ordered tree structure must be used instead of a graph. This section describes an extension to the graph model where the graph is flattened and ordered to provide a tree interface. The resulting tree-structured model imposes a linear ordering and uses several constructs which are not part of the graph model. Applications constructing a native binding from the tree model should not use these additional constructs and the imposed ordering for the preservation of important data.

To lay out graph nodes as a tree structure, a mechanism is needed to manage duplicate occurrences. This is solved with three node kinds: branch, leaf, and alias. The first occurrence of a scalar is represented by a leaf, the first occurrence of a collection is represented by a branch, and subsequent occurrences of either a collection or a scalar are represented by an alias. All tree nodes in this model have the following properties:

kind

A tree node may be one of three kinds, a branch, a leaf or an alias.

parent

The parent property gives access to the branch which holds the current tree node.

anchor

The anchor is a Unicode string which complies with the anchor production. The anchor is used to associate the first occurrence of a graph node with subsequent occurrences, via the alias tree node. This property is optional for leaf or branch nodes, provided that the scalar or collection represented does not occur more than once.

Note that when a tree node is converted to a graph node, the anchor, if any, is not converted. Likewise the parent property and the alias kind are not preserved as the graph node may participate in several collections.

Leaf tree nodes represent the first occurrence of a scalar in a given serialization.

type family

Like a scalar, each leaf is associated with a type family.

format

Unlike a scalar, each leaf is associated with a specific string format.

string value

Each leaf has a string value which is a string representation of the scalar according to the specific string format used.

When a leaf is converted into a graph node it becomes a scalar of the same type family. The scalar's value would be such that its string representation according to the specific format used would be identical to the leaf's string value. Note that the particular format used is not converted.

A pair is an ordered set of two tree nodes. The first member of the set is the key and the second member of the set is the value.

Branch tree nodes represent the first occurrence of a collection in a given serialization.

type family

Like a collection, each branch is associated with a type family.

pairs

A branch has an ordered set of zero or more pairs.

When a branch is converted into a graph node, three operations occur. The domain is constructed with the graph node for each key in its set of pairs. Likewise, the range is constructed with the graph node for each value in its set of pairs. Last, the function is constructed via assocation of key graph nodes to value graph nodes, as provided by the set of pairs. Note that the ordering of the pairs is explicitly not converted.

When serializing a YAML graph, every tree node is put into a single linear sequence within a given document through the branch pair ordering. With the composition of branches, this ordering becomes total, so that for any two distinct tree nodes in a serialization, one can be said to precede another.

For any two nodes or aliases, x and y we say that x precedes y when any of the following holds:

  • x is the parent of y.

  • x is a key and y is a value in a given pair.

  • x and y are nodes in two pairs within a branch, and the pair containing x comes before the pair containing y.

  • There exists a node z such that x precedes z and z precedes y.

To enhance readability, a YAML serialization extends the tree model with syntax styles, comments and directives. Although the parser may provide this information, applications should take care not to use these features to encode information found in a native binding.

The tree node is extended with a style property, which can have different values depending upon its kind.

leaf style

Leaf styles include eight nested styles and three in-line styles. All but the escaped and double quoted styles are limited to scalars having only printable characters.

branch style

Branch styles are series and keyed. The series style may only be used if the domain of the collection's function is the set of sequential positive integers starting at zero.

The syntax model allows optional comment blocks to be interleaved with the node blocks. Comment blocks may appear before or after any node block. A comment block can't appear in a nested leaf node block value.

comment

A comment is a series of zero or more Unicode characters complying with the comment productions.

Following are the syntax productions for the YAML serialization.

Characters are the basis for a serialized version of a YAML document. Below is a general definition of a character followed by several characters which have specific meaning in particular contexts.

Serialized YAML uses a subset of the Unicode character set. A YAML parser must accept all printable ASCII characters, the space, tab, line break, and all Unicode characters beyond 0x9F. A YAML emitter must only produce those characters accepted by the parser, but should also escape all non-printable Unicode characters if a character table is readily available.

[001] printable_char ::=
|
|
|
|
|
#x9
#xA | #xD | #x85
[#x20-#x7E]
[#xA0-#xD7FF]
[#xE000-#xFFFD]
[#x10000-#x10FFFF]
/* characters as defined by the Unicode standard, excluding most control characters and the surrogate blocks */

The range above explicitly excludes the surrogate block [#xD800-#xDFFF], DEL 0x7F, the C0 control block [#x0-#x1F], the C1 control block [#x80-#x9F], #xFFFE and #xFFFF. Note that in UTF-16, characters above #xFFFF are represented with a surrogate pair. DEL and characters in the C0 and C1 control block may be represented in a YAML serilization using escape sequences.

A YAML processor is required to support the UTF-32, UTF-16 and UTF-8 character encodings. If an input stream does not begin with a byte order mark, the encoding shall be UTF-8. Otherwise the encoding shall be UTF-32 (LE or BE), UTF-16 (LE or BE) or UTF-8, as signaled by the byte order mark. Note that as YAML files may only contain printable characters, this does not raise any ambiguities. For more information about the byte order mark and the Unicode character encoding schemes see the Unicode FAQ.

[002] byte_order_mark ::= #xFEFF /* the Unicode ZERO WIDTH NON-BREAKING SPACE character used to mark a UTF-32 or UTF-16 stream and determine byte ordering */

Indicators are special characters which are used to describe the structure of a YAML document.

[003] series_entry_indicator ::= '-' /* indicates a series entry */
[004] keyed_entry_separator ::= ':' /* separates a key from its value */
[005] series_inline_start ::= '[' /* starts an in-line series branch */
[006] series_inline_end ::= ']' /* ends an in-line series branch */
[007] keyed_inline_start ::= '{' /* starts an in-line keyed branch */
[008] keyed_inline_end ::= '}' /* ends an in-line keyed branch */
[009] branch_inline_separator ::= ',' /* separates in-line branch entries */
[010] nested_key_indicator ::= '?' /* indicates a nested key */
[011] alias_indicator ::= '*' /* indicates an alias node */
[012] anchor_indicator ::= '&' /* indicates an anchor property */
[013] transfer_indicator ::= '!' /* indicates a transfer method property */
[014] block_indicator ::= '|' /* indicates a block leaf */
[015] folded_indicator ::= ']' /* indicates a folded leaf */
[016] single_quote ::= ''' /* indicates a single quoted leaf */
[017] double_quote ::= '"' /* indicates a double quoted leaf */
[018] throwaway_indicator ::= '#' /* indicates a throwaway comment */
[019] reserved_indicators ::= '@' | '%' | '^' /* reserved */

Indicators can be grouped into three categories. The '-' and ':' space indicators are always followed by a white space character (space, tab or line break). If followed by any other character, these indicators are treated as content. The '[', ']', '{', '}' and ',' in line indicators are used to denote in-line branch structure and therefore must not be used as content text characters unless protected in some way. The remaining indicators are used to denote the start of various YAML elements and hence may used as internal content text character in most cases. The exact restrictions on the use of indicators as content text characters depend on the particular leaf style used.

The Unicode standard defines the following line break characters.

[023] line_feed ::= #xA /* ASCII line feed (LF) */
[024] carriage_return ::= #xD /* ASCII carriage return (CR) */
[025] next_line ::= #x85 /* Unicode next line (NEL) */
[026] line_separator ::= #x2028 /* Unicode line separator (LS) */
[027] paragraph_separator ::= #x2029 /* Unicode paragraph separator (PS) */
[028] line_break_char ::=
|
|
|
|
line_feed
carriage_return
next_line
line_separator
paragraph_separator
/* line break characters */

Line breaks can be grouped into two groups. Specific line breaks have well-defined sematics for breaking text into lines and paragraphs. The semantics of generic line break characters is not defined beyond ending a line.

Outside text content, YAML allows any line break to be used to terminate lines, and in most cases also allows such line breaks to be preceded by trailing line space characters. On output, a YAML emitter is free to emit non content line breaks using whatever convention is most appropriate. An emitter should avoid emitting trailing line spaces.

This section includes several common character range definitions.

[033] line_char ::=
-
printable_char
line_break_char
/* characters valid in a line */
[034] line_space ::= #x20 | #x9 /* whitespace valid in a line */
[035] line_non_space ::=
-
line_char
line_space
/* non space characters valid in a line */
[036] line_non_ascii ::=
-
line_char
[#x00-#x7F]
/* non-ASCII line characters */
[037] ascii_letter ::=
|
[#x41-#x5A]
[#x61-#x7A]
/* ASCII letters, A-Z or a-z */
[038] non_zero_digit ::= [#x31-#x39] /* 1-9 */
[039] decimal_digit ::= [#x30-#x39] /* 0-9 */
[040] hexadecimal_digit ::=
|
|
decimal_digit
[#x41-#x46]
[#x61-#x66]
/* 0-9, A-F or a-f */
[041] word_char ::=
|
|
decimal_digit
ascii_letter
'-'
/* characters valid in a word */

Serialized YAML uses text lines to convey structure. This requires special processing rules for white space (space, tab and line break) characters. These rules are compatible with Unicode's newline guidelines.

In a YAML serialization, structure is determined from indentation, where indentation is defined as a line break character followed by zero or more space characters.

Tab characters are not allowed in indentation unless a '#TAB' directive is used. If such a directive is used, each indentation tab is equivalent to a certain number of spaces determined by the specified tab policy.

A node must be more indented than its parent node. All sibling nodes must use the exact same indentation level. However the content of each such node may be indented independently.

The indentation level is used exclusively to delineate structure. Indentation characters are otherwise ignored. In particular, they are never taken to be a part of the value of serialized text.

[042] indent(n) ::= #x20 x n /* specific level of indentation */
[043] indent(<n) ::= indent(m) /* for some specific m such that m < n */
[044] indent(<=n) ::= indent(m) /* for some specific m such that m <= n */

Since the YAML serialization depends upon indentation level to delineate blocks, additional productions are a function of an integer, based on the indent(n), indent(<n) and indent(<=n) productions above.

Throwaway comments have no effect whatsoever on the tree or graph models represented in the file. Their usual purpose is to communicate between the human maintainers of the file. A typical example is comments in a configuration file.

A throwaway comment always spans a complete line. An explicit throwaway comment line consists of of some indentation, a '#' indicator, and arbitrary comment characters to the end of the line. Empty lines or lines containing only indentation spaces are taken to be an implicit throwaway comment.

A throwaway comment may appear before a document node or following any node. A throwaway comment may not appear inside a nested line leaf node, but may precede or follow such a node. When following a nested leaf value, the first comment line must be explicit and be less indented than the nested node value. Following comment lines are not restricted.

# These are three throwaway comment

# lines (the second line is empty).
this: |
    contains two lines of text, the
    # second of which starts with '#'.
# A comment may follow a leaf value.

A series of bytes is a YAML stream if, taken as a whole, it complies with the following production. Note that an empty stream is a valid YAML stream containing no documents.

A YAML stream may contain several independent YAML documents. A document header line is used to separate documents. This line must start with a document separator - '--' followed by a series of non-space characters. The same separator line must be used in all the document headers throughout the stream.

If no explicit header line is specified at the start of the stream, the parser should behave as if a header line containing '--- #YAML:1.0 #TAB:NONE' was specified.

--- ]
This YAML stream contains a single text value.
The next stream is a log file - a series of log
entries. Adding an entry to the log is a simple
matter of appending it at the end.
---
at: 2001-08-12 09:25:00.00
type: GET
HTTP: '1.0'
url: '/index.html'
---
at: 2001-08-12 09:25:10.00
type: GET
HTTP: '1.0'
url: '/toc.html'
# This stream is an example of a top level map.
invoice : 34843
date    : 2001-01-23
total   : 4443.52
# The following is a sequence of five documents.
# The first two contain an empty map, the second two
# an empty sequence, and the last an empty string.
--- {}
--- !map
--- []
--- !seq
---

Directives are instructions to the YAML parser. Like throwaway comments, directives are not reflected in the tree or graph models. Directives apply to a single document. It is an error for the same directive to be specified more than once for the same document.

YAML defines two directives, '#YAML' and '#TAB'. Additional directives may be added in future versions of YAML. A parser should ignore unknown directives with an appropriate warning. There is no provision for specifying private directives. This is intentional.

#YAML

The '#YAML' directive specifies the version of YAML the document adheres to. This specification defines version '1.0'.

A version 1.0 parser should accept documents with an explicit '#YAML:1.0' directive, as well as documents lacking a '#YAML' directive. Documents with a directive specifying a higher minor version (e.g. '#YAML:1.1') should be processed with an appropriate warning. Documents with a directive specifying a higher major version (e.g. '#YAML:2.0') should be rejected with an appropriate error message.

#TAB

Since different systems treat tabs differently, portability problems are a concern. Therefore, the default tab policy of YAML is conservative ('#TAB:NONE'); don't allow them in indentation. However, for some users, their editor may make it difficult to not use tabs. In this case, the '#TAB' directive is available so that the tab policy is explicitly provided to the YAML parser. Note that tab characters in text content are always valid and must be preserved by the parser, regardless of the tab policy used.

YAML supports the following tab policies:

#TAB:NONE

This default policy forbids the use of tabs in indentation. If such a tab character is detected, the parser must treat it as an error. The error message should refer to the need for providing an explicit tab policy for tabs to be used as indentation characters.

Many editors can be configured such that pressing the tab key is automatically converted to the insertion of a appropriate number of spaces into the edited file, and in general support convenient editing of indented blocks without making use of tab characters. Where possible, YAML editors should be configured to using this indentation policy, as it is the only truly portable one. The https://yaml.org/editors page contains instructions on configuring known editors to use this policy.

#TAB:N (for some positive integer N)

Tab characters in indentation are equivalent to the number of spaces which would bring the indentation level to the next multiple of N.

Almost every editor supports this type of policy, with '#TAB:8' being the most common, followed by '#TAB:4'. Most editors also allow users to configure the value of N. Typically an editor providing this flexibility can also be configured to use the '#TAB:NONE' policy as described above.

#TAB:N:HARD (for some positive integer N)

Tab characters in indentation are equivalent to exactly N spaces. This type of policy has much less support by editors. However, if an editor does use this type of policy, it is less likely to allow configuration to using a different type.

When either a '#TAB:N' or a '#TAB:N:HARD' policy is used, the parser must expand indentation tabs to spaces accordingly. Each tab, when expanded to spaces, must not span beyond the indentation into the serialized text. While this is an error, parsers should recover from it with a warning, by assigning some of the spaces to the indentation and some to the serialized text.

A serialization node begins at a particular level of indentation, n, and its content is indented at some level >n. A serialization node can be either a branch (keyed or series), a leaf (nested or in-line) or an alias.

A YAML document is a normal node. However a document can't be an alias (there is nothing it may refer to). Also if the header line is omitted the first document must be a nested (not in-line) branch.

Each serialization node may have anchor and transfer method properties. These properties are specified in a properties list appearing before the node value itself. For a top level node (a document), the properties appear in the document header line, following the directives (if any). It is an error for the same property to be specified more than once for the same node.

The transfer method property specifies how to deserialize the associated node. It includes the type family for the node and optionally the specific format used, separated by a '|' character.

A type family may be either public or private. A public type family name is a globally unique URI. A private type family names must begin with a '!' character. Such type families should not be expected to have consistent semantics in different documents.

By providing an explicit transfer property to a node, implicit typing is prevented. However, an explicit empty transfer method property can be used to force implicit typing to be applied to a non-simple leaf value.

Escaping

URIs support a limited ASCII-based character set. Hence, when parsing a URI type family name, the parser must convert any non-ASCII character to UTF-8 encoding, then use '%' style escaping to represent the resulting bytes.

In general, expanding '%' escaped characters may change the semantics of a URI. Hence the parser must accepts such sequences and pass them unmodified to the application.

The parser must also accept YAML style escape sequences. These must be converted to '%' style escape sequences as described above even if the specified character is a valid printable ASCII URI character. Thus the parser must convert the YAML escape sequence '\x30' to the URI escape sequence '%30' rather than to the digit '0'.

Prefixing

YAML provides convenient shorthand for the common case where a node and (most of) its decsendents have public types families whose URIs share a common prefix.

For this case, YAML allows using the '^' character to separate the ancestor node's type family URI into a prefix and a suffix. The parser does not consider the separator to be part of type family name.

When the parser encounters a descendant node whose type family name begins with '^', it appends the ancestor node's prefix to it. Again the '^' character is not taken to be part of the name.

It is possible for a descendant node to establish a different prefix. In this case the node may not make use of its ancestor's node prefix. It must specify a full type family name URI, separated into a prefix and suffix as above.

It is an error for a node's type family name to begin with '^' unless it has an ancestor node establishing a prefix. However, a node may establish a prefix even if none of its decendents make use of it.

Note that the type prefix mechanism is purely syntactical and does not imply any additional semantics. In particular, the prefix must not be assumed to be an identifier for anything.

Shorthands

To increase readability, YAML provides shorthand notations for certain type family URIs. Like the prefixing mechanism, shorthand notations are merely syntactical and do not imply any additional semantics. Note that it is valid to use a shorthand type family in order to establish a prefix.

  • If the type family contains no ':' and no '/' characters it is prefixed with https://yaml.org/. Thus the parser must report a node with the type family !seq as if it was written using the full !https://yaml.org/seq notation.

  • Otherwise, if the type family begins with a single word followed by a '/' character, it is assumed to belong to a sub-domain of yaml.org. Hence the parser must report a node with the type family !perl/Text::Tabs as if it was written using the full !http://perl.yaml.org/Text::Tabs notation.

    Each domain language.yaml.org will include all globally unique types of the language which aren't covered by the set of language-independent types. Globally unique types for each language include any built-in types and any standard library types. For languages such as Java and C#, all type names based on reverse DNS strings are globally unique. For languages such as Perl, which has a central authority (CPAN) for managing the global namespace, all the types sanctioned by the central authority are globally unique. The list of supported languages and their types is maintained as part of the YAML type repository.

  • Otherwise, if the type family contains a '/' before any ':' characters it may include, it is prefixed with http://. Therefore the parser must report a node with the type family !clarkevans.com/timesheet as if it was written using the full !http://clarkevans.com/timesheet notation.

  • Otherwise, the type family contains a ':' before any '/' characters it may include, is assumed to begin with an explicit URI scheme, and is preserved. Hence the parser must report a node with the type family !modem:+3585551234567;type=v32b?7e1;type=v110 as it is written.

# All entries in the series
# have the same type and value.
- 10.0
- !float 10
- !yaml.org/^float '10'
- !https://yaml.org/float ]\
  1\
  0
# Private types are per-document.
---
pool: !!ball
   number: 8
   color: black
---
bearing: !!ball
        material: steel
# 'http://company.tld/invoice' is some type family.
invoice: !company.tld/^invoice
  # 'seq' is a shorthand for 'https://yaml.org/seq'.
  # This does not effect '^customer' below
  # because it is does not specify a prefix.
  customers: !seq
    # '^customer' is a shorthand for the full
    # notation 'http://company.tld/customer'.
    - !^customer
      given : Chris
      family : Dumars
# It is possible to use XML namespace URIs as
# YAML namespaces. Using the ancestor's URI
# allows specifying it only once. The $ separates
# between the XML namespace URI and the tag name.
doc: !http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd$^html
 - !^body
  - !^p This is an HTML paragraph.

An anchor is a property which can be used to mark a serialization node for future reference. An alias node can then be used to indicate additional inclusions of an anchored node by specifying the node's anchor.

Once an anchor is used to mark a node, an alias should be used to indicate additional occurrences of the node in the graph. An alias refers to the most recent preceding node having the same anchor.

An alias node only exists in the syntax and tree models. When converted to the graph model, an alias node becomes a second occurrence of the anchored node.

It is an error to have an alias use an anchor which does not occur previously in the serialization of the document.

anchor : &A001 This leaf has an anchor.
override : &A001 ]
 The alias node below is a
 repeated use of this value.
alias : *A001

Branch nodes come in two styles, series and keyed. Each style has two variants, nested and in-line.

A series node is the simplest node style. it contains a series of sub-nodes at a higher indentation level. An in-line style is available for short, simple series.

empty: []
inline: [ one, two, three ]
nested:
 - First item in top series
 -
  - Subordinate series entry
 - ]
  A multi-line
  series entry
 - Sixth item in top series

A keyed node is an association of unique keys with values. It is an error for two equal key entries to appear in the same keyed node. In such a case the parser may continue processing, ignoring the second key and issuing an appropriate warning. This strategy preserves a consistent information model for streaming and random access applications.

An in-line form is available for short, simple keyed nodes. Also, if a keyed node has no properties, it may start in-line in a series entry.

empty: {}
inline: { one: 1, two: 2 }
nested:
 first : First entry
 second:
  key: Subordinate keyed
 third:
  - Subordinate series
  - !map
  - Previous keyed is empty.
  - A key: value pair in a series.
    A second: key:value pair.
  - The previous entry is equal to the following one.
  -
   A key: value pair in a series.
   A second: key:value pair.
 !float 12 : This key is a float.
 ? ]
  ?
 : This key had to be protected.
 ? ]\
  \a
 : This key had to be escaped.
 "\b": Another way to escape
 ? ]
  This is a
  multi-line
  plain key
 : ]
  Whose value is
  also multi-line.
 ?
  - This key
  - is a series
 :
  - With a series value.
 ?
  This: key
  is a: mapping
 :
  with a: mapping value.

While most of the document productions are fairly strict, the leaf production is generous. It offers three in-line style variants and eight nested style variants to choose from depending upon the readability requirements.

Throwaway comments may follow a leaf node, but may not appear inside one. The first comment line following a nested leaf node must be explicit and less indented than the nested leaf value. Further comment lines are unrestricted. Comment lines following an in-line leaf node are unrestricted.

Empty lines in nested leaf blocks appearing before the trailing explicit comment line, if any, are interpreted as content rather than as implicit comments. Such lines may be less indented than the text content.

[099] less_indented_empty_line(n) ::= indent(<n) /* empty line with optional indentation */

The style variant of a nested leaf node is defined using the following three independent properties: folding, escaping, and chomping. In addition, a nested leaf may have explicit indentation.

Block leaf values are indicated by a '|' character. In such values, line break characters are taken to be a part of the serialized value.

Each generic line break is converted to a single LF character. Specific line breaks are preserved. This functionality is indicated by the use of the normalized_line_break production defined below.

On output, a YAML emitter is free to serialize LF characters using whatever convention is most appropriate. Escaping must be used to serialize significant CR and NEL content characters. LS and PS must be preserved.

Folded leaf values are indicated by a ']' character. In folded values, in addition to being normalized, line break characters are subject to line folding. Line folding provides increased readability by allowing long text lines to be broken.

In a folded leaf, a single normalized line feed is converted to a single space (#x20). When two or more consecutive (possibly indented) normalized line feeds are encountered, the parser does not convert them into spaces. Instead, the parser ignores the first of the line feeds and preserves the rest. Thus a single line feed can be serilized as two, two line feeds can be serialized as three, etc. When this functionality is implied, the folded_internal_line_breaks(n) production below will be used.

When a folded value starts with one or more line feed characters, the parser preserves them, neither converting a single line feed to a space not stripping away the first line feed in a series. When this functionality is implied, the folded_leading_line_feeds(n) production below will be used.

When a folded value ends with one or more line feed characters, the parser always ignores the first one and preserves the rest. When this functionality is implied, the folded_trailing_line_breaks(n) production below will be used.

The combined effect of the three processing rules above is that each empty line within a folded leaf represents a single line feed character, be it at the start, middle or end of the value.

Note that folding only applies to generic line break characters. Specific line break characters are preserved, and may be safely used to indicate line/paragraph text structure even when line folding is done.

Escaped leaf values are indicated by a '\' character. In escaped values, arbitrary Unicode characters may be specified using escape codes. Plain (non-escaped) values are restricted to printable Unicode characters.

An escaped line break is ignored, allowing long lines in an escaped value to be broken at arbitrary positions, regardless of folding.

In contrast, plain leaf values may freely make use of the '\' as a text character.

Typically the indentation level of a nested leaf value is detected from its first content line. This detection fails when this first line is empty, contains a leading '#' character, or contains leading white space characters.

In such cases YAML requires that the indentation level for the leaf value text content be given explicitly. This level is specified as an integer number of the additional number of indentation spaces for the text content.

It is always valid to specify an explicit indentation level, though emitters should not do so in cases where detection succeeds. It is an error for detection to fail when there is no explicit indentation specified.

A nested leaf node may be in one of eight style variants defined by the three nested leaf properties.

A plain block is the simplest style variant of a nested leaf. The only processing done is end-of-line normalization and stripping away the indentation.

empty: |
detected: |
 The \ character may be freely
 used. Leading white space
    is significant.

 All line breaks are significant,
 including the final one. Thus
 this value contains one empty
 line and ends with a line break,
 but does not start with one.
# Comments may follow a nested
 # leaf value. Once the first
  # comment line is seen, they
   # can be at any indentation
    # level, or even empty lines.

# Explicit indentation must
# be given in all the three
# following cases.
leading spaces: |2
      This value starts with
  four spaces. It ends with
  two line breaks.

leading line break: |2

  This value starts with
  a line break and ends
  with one.
leading comment indicator: |2
  # first line starts with a
  #. This value does not start
  with a line break but ends
  with one.
# Explicit indentation may
# also be given when it is
# not required.
redundant: |2
  This value is indented 2 spaces.

The chomped block style variant is identical to the plain block, except that the trailing line breaks are subject to chomping.

empty: |-
detected: |-
 All line breaks are significant,
 except for the trailing ones.
 Thus this value does not end
 with a line break.

# Comments may follow.

The escaped block style variant is identical to the plain block, except that escape sequences are expanded in it, and escaping a line break causes it to be ignored.

empty: |\
detected: |\
 Escape sequences may be used,
 for example this\nforces a
 line break and th\
 is isn't one. Quotes " '
 and other indicators may be
 freely used, but the \\
 character must be escaped.
explicit: |\2

  This value starts with
  a line break but does
  not end with one.\
# Comments may follow.

The chomped escaped block style variant combines stripping away the trailing line breaks as in a chomped block and expanding escape sequences as in an escaped block.

empty: |\-
detected: |\-
 Trailing line breaks
 are stripped, so this
 value does not end
 with a line break.

escaped: |\-
 Escaped line breaks
 are not chomped so
 this value ends with
 a single line break.\n

ignored: |\-
 It is possible to
 explicitly ignore
 a trailing line break,
 for example in case
 it is an LS or PS
 character.\
# Comments may follow.

The plain folded style variant is identical to the plain block, except that line breaks are subject to line folding.

empty: ]
detected: ]
 Line feeds are converted
 to spaces, and the final
 line break series is
 clipped, so this value
 contains no line breaks.
explicit: ]2

  An empty line, either
  at the start, end of
  in the value:

  Is interpreted as a
  line break. Thus this
  value contains three
  line breaks.

# Comments may follow.

The chomped folded style variant combines stripping away the trailing line breaks as in a chomped block and line folding as in the plain folded style variant.

empty: ]-
detected: ]-
 The final sequence of
 line breaks is chomped,
 so this value contains
 no line breaks.

# Comments may follow.

The escaped folded style variant combines expanding escape sequences as in an escaped block and line folding as in the plain folded style variant.

empty: ]\
detected: ]\
 Escaped line feeds are not
 converted to a space, so
 this \n is a line feed.
explicit: ]\2

  This value starts with
  a line feed, but doesn't
  end witj one even though
  it has a trailing empty
  line.\

# Comments may follow.

The chomped escaped folded style variant combines stripping away the trailing line breaks as in a chomped block, expanding escape sequences as in an escaped block, and line folding as in the plain folded style variant.

empty: ]\-
detected: ]\-
 Trailing line feeds are
 chomped, but escaped ones
 are preserved, so this
 value ends with a single
 line feed.\n

# Comments may follow.

An in-line leaf may be in one of three style variants. The double quoted style variant supports escaping and can be used to represent arbitrary Unicode strings. The single quoted style variant is limited to printable Unicode characters. The simple style variant is further restricted to not contain most indicator characters or leading or trailing space characters.

The single quoted style variant is indicated by surrounding ''' characters. Therefore, within a single quoted leaf such characters need to be escaped. No other form of escaping is done, limiting single quoted leaves to printable characters. Also, single quoted leaves may not contain any line break characters.

empty: ''
second: '! : \ etc. can be used freely.'
third: 'a single quote '' must be escaped.'

The double quoted style variant adds escaping to the single quoted style variant. This is indicated by surrounding '"' characters. Escaping allows arbitrary Unicode characters to be specified at the cost of some verbosity: escaping the printable '\' and '"' characters. It is an error for a double quoted value to contain invalid escape sequences.

empty: ""
second: "! : etc. can be used freely."
third: "a \" or a \\ must be escaped."
fourth: "this value ends with an LF.\n"

The simple style variant is a restricted form of the single quoted style variant. As it has no identifying markers, it may not start or end with white space characters, may not start with most indicators, and may not contain certain indicators. Also, a simple leaf is subject to implicit typing. This can be avoided by providing an explicit transfer method property.

empty:
second: The value of the previous key is the empty string.
third: 12
fourth: The above entry is an integer.

A transfer method is the combination of the type family and string format used to serialize a value in a YAML document stream. This section provides a list of common type families and their their associated string formats defined under the yaml.org domain.

Every serialization node has, by definition, a transfer method (type family and string format). YAML provides three mechanisms for identifying the transfer method of a node.

Default Typing

By default the parser assigns the string type family to all leaf nodes (except for simple leaves), the map type family to all keyed nodes, and the seq type family to all series nodes.

Implicit Typing

All simple leaves are subject to implicit typing, unless they are annotated with an explicit transfer method property. For each type family, there is a set of implicit string formats, and each such format has a regular expression. The parser compares the leaf value with the list of these regular expressions. If the value matches one of these expressions, it is parsed as if it were explicitly annotated with the appropriate type family and format. It is an error for a value to match more than one such regular expression.

The active set of implicit transfer methods depends upon the application. Regular expressions for implicit string formats must start with '^`' if they are not defined in this specification or accepted into the YAML type repository. Values matching such private implicit transfer methods therefore always begin with the '`' character. This prevents private implicit transfer methods from interfering with public ones.

Explicit Typing

A node may be given an explicit transfer method property, specifying the node's type family and optionally its string format. If no format is given, the parser matches the value with the regular expressions of each of the implicit and explict string formats provided by the type family to determine the specific format used. It is an error for a value to match more than one such regular expression.

Using an explicit transfer method is required when default and implicit typing fail to identify the intended type family and string format for a node. Common cases are handling application-defined types and specifying empty sequences and maps.

Following is a list of common type families and their associated string formats defined under the yaml.org domain. YAML requires support for the sequence, map and string type families. While the other type families are not mandatory, they usually map to native data types in most programming languages, so using them promotes interoperability with other YAML systems.

Additional common type families are defined in the YAML type repository available at https://yaml.org/repository. An application may also use private type families or public type families defined on the basis of some URI or DNS domain name. The exact set of transfer methods used in a document is a part of the document's schema, and is tied to the expected document graph structure, the set of valid map keys, etc.

This type family is used for series nodes unless they are given an explicit transfer method property. Example bindings include the Perl array, Python's list or tuple, and Java's array or vector.

name: https://yaml.org/seq
styles:

Series, keyed by integers, empty leaf.

definition:

Collections indexed by sequential integers starting with zero.

Applying this type family to an empty leaf provides a natural syntax for representing an empty sequence.

# The following is an empty
# top level sequence.
--- !seq
---
# An empty sequence.
empty: !seq
---

In some applications, large sequences may contain only a small number of non-null entries. While it is possible to serialize such sparse sequences using null values, this is awkward. YAML allows to serialize such sequences using the mapping style with an explicit sequence type family. The only supported keys are integers, serving as zero-based sequence entry indices.

# The following map style node is
# loaded to a sequence, with
# unspecified entries containing
# a null value.
sparse sequence: !seq
    2: Third entry
    4: ~
# The following sequence node is
# loaded into an identical
# in-memory sequence, which has
# a seperate identity.
equal sequence:
 - ~
 - ~
 - Third entry
 - ~
 - ~

This type family is used for keyed nodes unless they are given an explicit transfer method property. Example bindings include the Perl hash, Python's dictionary, and Java's hash table.

name: https://yaml.org/map
styles:

Keyed, series, empty leaf.

definition:

Associative container, where each key is unique in the association and mapped to exactly one value.

Applying this type family to an empty leaf provides a natural syntax for representing an empty map.

# The following is an empty top level map.
--- !map
---
# An empty map.
empty map: !map

If the set of keys of a map happens to be all the integers in the range 0 to some N, YAML allows serializing the map using the series style with an explicit map type family.

# The following series style node is
# loaded to a map.
integer map: !map
 - Value for integer key '0'
 - Value for integer key '1'
 - Value for integer key '2'
# The following keyed style node is
# loaded to an equal in-memory map,
# which has a separate identity.
equal map:
 2: Value for integer key '2'
 0: Value for integer key '0'
 1: Value for integer key '1'

This type family is used for all leaf styles with the exception of simple leaves, unless they are given an explicit transfer method property. It is also used as the implicit type for all simple leaves starting with an alphabetic character. Note that all non-ASCII characters are assumed to be alphabetic for this purpose. This allows the detection pattern to be independent of the Unicode character properties table.

This type is usually bound to the native language's string or character array construct.

Name: https://yaml.org/str
Styles:

Leaf.

definition:

Unicode strings, a series of zero or more Unicode characters.

formats:

explicit
canonical

any ~= .* /* any sequence of characters */

implicit

alpha_first ~= [_a-zA-Z\x80-\
\Uffffffff].*
/* any sequence of characters starting with an alphabetic character */

Specifying an explicit string type family is required to bypass implicit typing for a simple leaf. The same effect can be achieved by converting it to another leaf style.

# The following leaves are
# loaded to the string
# value '1' '2'.
- !str 12
- '12'
- "12"
- ]
 12
- ]\
 1\
 2
- |-
 12

The null type family accepts simple leaves with the value '~' and converts them into any native null-like value (e.g., undef in Perl, None in Python). A null value is used to indicate the lack of a value. Note that in most programming languages a map entry with a key and a null value is valid and different from not having that key in the map.

Name: https://yaml.org/null
Styles:

Simple leaf.

definition:

Devoid of value.

formats:

implicit
canonical

tilde ~= ~ /* single tilde character */
first: ~
second:
 - ~
 - Second entry.
 - ~
 - This sequence has 4 entries, two with values.
three:
 This map has three keys,
 only two with values.

The pointer type family accepts a keyed node with a single key, '=', and is loaded into any native pointer-like data type, pointing to the value given for that key (e.g., a hard reference in Perl). Note that this is not necessarily the native data type used to implement alias nodes. For example, in Java aliases are directly supported, but pointers must be emulated using a special class.

Name: https://yaml.org/ptr
Styles:

Keyed.

definition:

A hard reference, explicit memory address.

Perl: |
 $map{YAML} = \"content";
# The following map is loaded
# into a pointer to a text string.
YAML: !ptr
 = : content

The integer represents arbitrarly sized mathematical integers less than infinity. Integers can be formatted using the familar decimal notation, or may have a leading '0x' to signal hexadecimal, or a leading '0' to signal an octal base. Leaves of this type should be represented by a native integer data type, if possible. However, there are cases where an integer provided may overflow the native type's storage capability. In this case, the loader should find some manner to round-trip the integer, perhaps as a string value. In general, integers representable using 32 binary digits should safely round-trip through most systems.

Name: https://yaml.org/int
Styles:

Simple leaf.

definition:

Mathematical integers.

formats:

canonical

int ~= 0|[-]?[1-9][0-9]* /* canonical integer format */

implicit

dec ~= [-+]?(0|[1-9][0-9]*) /* base 10 signed decimal integer format */

implicit

oct ~= [-+]?0[0-7]+ /* base 8 integer format */

implicit

hex ~= [-+]?0x[0-9a-fA-F]+ /* base 16 integer format */
canonical: 12
decimal: +12
octal: 014
hexadecimal: 0xC

The floating point type family handles approximations to real numbers. This should be loaded to some native float data type. The loader may choose from a range of such native data types according to the size and accuracy of the floating point value. The valid range and accuracy depend on the loader, though 32 bit IEEE floats should be safe.

Name: https://yaml.org/float
Styles:

Simple leaf.

definition:

Floating point approximation to real numbers.

formats:

canonical

sci ~= [-]?[0-9]\.([0-9]*[1-9])\
?e[-+](0|[1-9][0-9]+)
/* canonical (scientific notation) floating point format */

implicit

exp ~= [-+]?[0-9]+\.[0-9]*\
[eE][-+][0-9]+
/* exponential notation floating point format */

implicit

fix ~= [-+]?[0-9]+\.[0-9]* /* fixed point notation floating point format */
canonical: 1.23e-1
exponential: 12.30e-02
fixed: 0.1230

YAML supports a single date format which is a strict subset of the ISO 8601 standard and the formats proposed by the W3C note on datetime.

Name: https://yaml.org/date
Styles:

Simple leaf.

definition:

Gregorian date.

formats:

implicit
canonical

ymd ~= [0-9][0-9][0-9][0-9]\
-[0-9][0-9]-[0-9][0-9]
/* Date in YYYY-MM-DD format */
date: 2001-12-14

YAML supports a single time of day format which is one of many formats defined in the ISO 8601 standard. The format chosen was motivated by the W3C note on this issue.

Name: https://yaml.org/time
Styles:

Simple leaf.

definition:

Time of day.

formats:

implicit
canonical

time ~= [0-9][0-9]:[0-9][0-9]\
:[0-9][0-9](\.[0-9]*[1-9])?
/* Canonical time of day HH:MM:SS.SS (24 hours) format */

implicit

hms ~= [0-9][0-9]:[0-9][0-9]\
:[0-9][0-9](\.[0-9]*)?
/* Generic time of day HH:MM:SS.SS (24 hours) format */
canonical: 21:59:43.1
hms: 21:59:43.10

A timestamp denotes a particular point in time, which is a combination of a date and a time of day. Hence the format for a timestamps builds upon the format for a date and a time. The caninical combination chosen is a subset of a valid ISO 8601 format. A similar, more readable format, is also supported.

Name: https://yaml.org/timestamp
Styles:

Simple leaf.

definition:

A point in time.

formats:

canonical

timestamp ~= [0-9][0-9][0-9][0-9]-\
[0-9][0-9]-[0-9][0-9]T\
[0-9][0-9]:[0-9][0-9]:\
[0-9][0-9](\.[0-9]*[1-9])?Z
/* Canonical specific ISO 8601 format based on UTC */

implicit

ymdhmsz ~= [0-9][0-9][0-9][0-9]-\
[0-9][0-9]-[0-9][0-9]T\
[0-9][0-9]:[0-9][0-9]:\
[0-9][0-9](\.[0-9]*[1-9])?\
(Z|[-+][0-9][0-9](:[0-9][0-9])?)
/* A valid ISO 8601 timestamp format variant */

implicit

ymd_hms_z ~= [0-9][0-9][0-9][0-9]-\
[0-9][0-9]-[0-9][0-9] \
[0-9][0-9]:[0-9][0-9]:\
[0-9][0-9](\.[0-9]*)? \
(Z|[-+][0-9][0-9](:[0-9][0-9])?)
/* Space separated (non ISO 8601) format for enhanced readability */
canonical: 2001-12-15T02:59:43.1Z
valid iso8601: 2001-12-14T21:59:43.10-05:00
space separated: 2001-12-14 21:59:43.10 -05:00

The binary type family accepts the base64 format and deserializes it into some native binary data type (e.g., byte[] in Java). This is the recommended way to store such data in YAML files. Note however that many forms of binary data have internal structure which may benefit from being represented as YAML nodes (e.g. the Java serialization format).

Name: https://yaml.org/binary
Styles:

Leaf.

definition:

Binary data, a series of zero or more octets (8 bit values).

formats:

canonical

binary ~= Clean base64 /* Base64 encoded data without any white space characters */

canonical

base64 ~= Generic base64 /* Base64 encoded data as per RFC2045 */
canonical: !binary ]\
 R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf\
 n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW\
 NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++\
 f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg\
 d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN\
 AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww\
 EeECcgggoBADs=
base64: !binary ]
 R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf
 n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW
 NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++
 f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg
 d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN
 AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww
 EeECcgggoBADs=
description: ]
 The binary value above is a tiny arrow
 encoded as a gif image.

The special key type family is used for special YAML defined items, which are used as map keys to denote structural information.

Name: https://yaml.org/special
Styles:

Simple leaf (or none).

definition:

Special mapping keys.

formats:

implicit
canonical

special ~= =|// /* serializable special keys */

virtual
canonical

virtual ~= !|\||&|\* /* non serializable special keys */

All special keys stand for special in-memory values which are different from any value in any other type family. Specifically, these special in-memory values must not be implemented as string values.

The '=' key is used to denote the "default value" of a map. In some cases, it is useful to migrate a schema so that a scalar value is replaced with a collection. A processor may present a "scalar value" method which provides the value directly if the node is a scalar, or, returns the value of this special key if the node is a collection. If applications only ask for the scalar value, then the schema may freely grow over time replacing scalar values with richer data constructs without breaking older processing systems.

The '//' key is used to attach a note or persistent comment to a map. A simple filter can remove these notes before reaching the application, while allowing such comments to survive round-trips and to be manipulated as normal data when necessary.

The rest of the keys should not be used in serialized YAML documents. Their names are merely a convention for representing the appropriate special in-memory values. Hence these keys are called "virtual keys".

Virtual keys are used when a YAML parser encounters a valid YAML value of an unknown transfer method. For a schema-specific application, this is not different from encountering any other valid YAML document which does not satisfy the schema. Such an application may safely use a parser which rejects any value of any unknown transfer method, or discards the transfer method property with an appropriate warning and parses the value as if the property was not present.

For a schema-independent application (for example, a hypothetical YAML pretty print application), this is not an option. Parsers used by such applications should encode the value instead. This may be done by wrapping the value in a map containing virtual special keys. The '!' key denotes the unsupported type family, and the '|' key denotes the format used. In some cases it may be necessary to encode anchors and alias nodes as well. The '&' and '*' keys are used for this purpose.

This encoding should be reversed on output, allowing the application to safely round-trip any valid YAML document. In-memory, the encoded data may be accessed and manipulated in a standard way using the three basic data types (map, sequence and string), allowing limited processing to be applied to arbitrary YAML data.

annotated text:
 - This text contains
 -
  = : colored
  color : red
 - characters.
"!": These three keys
"&": had to be quoted
"=": and are normal strings.
# NOTE: the following encoded node
# should NOT be serialized this way.
encoded node :
 !special '!' : '!type'
 !special '&' : 12
 = : value
# The proper way to serialize the
# above structure is as follows:
node : !!type &12 value
commented: !!point
 //: This is the center point.
 x : 12
 y : 3