Home » YAML Syntax

YAML Syntax

In this section, we will learn about the structural requirement of YAML. In YAML, the documents are a collection of key-value pairs where the value can be complex as a tree or simple as a string. We will use spaces instead of taps while indenting the YAML. Indentation plays a very important part in the YAML file. Indentation is used to group thing that goes together. In indentation, the character will not consider as a part of content information.

In YAML, indentation represents the structure. Dashes (-) are used to represent the lists and colons(:) are used to represent the key-value pair.

Example 1:

The above example shows a key-value mapping indentation. It has an indentation under the datacenter. The two values under datacenter are part of datacenter mapping. They are associated with each other because they have two space indents before the actual key that is location and cab.

Example 2:

This shows a key-value mapping. Here, we use a colon for key-value pairs. The key is host, and the value is phl-42.

Example 3:

This example shows a list indentation. It also has indentation because it has a list under animals. It contains the dashes to indicate that it is a list, not just a key-value.

YAML Characters:

  • YAML is made to support Unicode. The problem is that all Unicode is not included in that.
  • YAML can support anything in the C0/C1 blocks, which are called the control blocks. These control blocks don’t have any actually represented symbols like letter ‘a’ or ‘colon’. These are the special or structural bits of Unicode that is used to show the end of a transmission.
  • There are some exceptions in YAML like it can support tabs as long as they are not used in the indentation. YAML also supports line feeds, delete symbol, and next line symbol.
  • YAML does not support surrogates, which is a combination of 16-bit Unicode characters.
  • YAML does not support all types of encoding. It only supports UTF-8, UTF-16, and UTF-32. If we want to make our YAML compatible with JSON, we have to use the UTF-32.

Indicator Characters

It includes a special semantic. The content of the YAML document is described by this semantic as follows:

S. N. Character Functionality
1 : It is used to describe the mapping value.
2 It describes the entry of the block sequence.
3 , It describes the entry of flow collection.
4 ? It is used to describe the mapping key.
5 ! It describes the tag of a node.
6 & It describes the anchor property of a node.
7 | It is used to describe the literal block scalar.
8 # It is used to describe the comments.
9 > It is used to describe the folded block scalar.
10 { It is used to start the mapping of flow.
11 } It is used to end the mapping of flow.
12 [ It is used to start the sequence of flow.
13 ] It is used to end the sequence of flow.
14 % It describes the use of directives.
15 * It is used to describe the alias node.

Next TopicYAML Datatypes

You may also like