Getting started with yaml
YAML is a recursive acronym for "
Language". It is a human readable data serialization standard for all programming languages.
Basic Yaml syntax
YAML is a text based format allowing to store structured data in a hierarchy. YAML is designed to be human and machine readable with a minimum of overhead. The YAML specification can be found at yaml.org. There is also a reference card
Comments start with
# and go till newline, comments must be separated from other tokens by whitespace. Whitespace isn't free, indentation must be spaces, not tabs. YAML will consider that lines prefixed with more spaces than the parent key are contained inside it. Moreover, all lines must be prefixed with the same amount of spaces to belong to the same map.
YAML has sequences and mappings as collection types, both can be represented in flow and block style.
An sequence of scalar strings in YAML looks like:
A mapping consists of key/value pairs:
Basic YAML Types
Block Style Mappings
With implicit keys:
With implicit and explicit keys:
another key and
[1, 2, 3] are keys of the same mapping, although they use different key styles.
Note that for a
# to introduce a comment, it must either
- occur at the beginning of a line, or
- be preceded by whitespace.
# must always be followed by whitespace.
# inside quoted scalars never start comments.
# may introduce comments at the end of block scalars, but therefore, it must be less indented than the block scalar's base indentation (which is usually determined by the indentation of its first non-empty line).
YAML supports three styles of escape notation:
a. space: " "
b. colon: ":"
c. ampersand: "&"
a. space: "\u0020"
b. single quote: "\u0027"
c. double quote: "\u0022"
a. double quote in single quote: 'Is "I always lie" a true statement?'
b. nested double quote: " She said, "I quit" "
c. nested single quote: ' He was speechless: '' '
Splitting text strings over multiple lines
YAML Sequential Data
Same list level: