YAML - Syntax Characters


Various types of characters are used for various functionalities. This chapter talks in detail about syntax used in YAML and focuses on character manipulation.

Indicator Characters

Indicator characters include a special semantics used to describe the content of YAML document. The following table shows this in detail.

Sr.No. Character & Functionality
1

_

It denotes a block sequence entry

2

?

It denotes a mapping key

3

:

It denotes a mapping value

4

,

It denotes flow collection entry

5

[

It starts a flow sequence

6

]

It ends a flow sequence

7

{

It starts a flow mapping

8

}

It ends a flow mapping

9

#

It denotes the comments

10

&

It denotes node’s anchor property

11

*

It denotes alias node

12

!

It denotes node’s tag

13

|

It denotes a literal block scalar

14

>

It denotes a folded block scalar

15

`

Single quote surrounds a quoted flow scalar

16

"

Double quote surrounds double quoted flow scalar

17

%

It denotes the directive used

The following example shows the characters used in syntax −

%YAML 1.1
---
!!map {
   ? !!str "sequence"
   : !!seq [
      !!str "one", !!str "two"
   ],
   ? !!str "mapping"
   : !!map {
      ? !!str "sky" : !!str "blue",
      ? !!str "sea" : !!str "green",
   }
}

# This represents
# only comments.
---
!!map1 {
   ? !!str "anchored"
   : !local &A1 "value",
   ? !!str "alias"
   : *A1,
}
!!str "text"
Advertisements