Skip to main content

YAML Syntax Characters

Various types of characters have different meaning in YAML syntax.

  • 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 are used to show the end of a transmission.
  • There are some exceptions in YAML. For example, 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 you want to make our YAML compatible with JSON, you have to use the UTF-32.

Indicator Characters

Indicator characters include a special semantics used to describe the content of YAML document.

CharacterFunctionality
-It denotes a block sequence entry
?It denotes a mapping key
:It denotes a mapping value
,It denotes flow collection entry
[It starts a flow sequence
]It ends a flow sequence
{It starts a flow mapping
}It ends a flow mapping
#It denotes the comments
&It denotes node’s anchor property
*It denotes alias node
!It denotes node’s tag
|It denotes a literal block scalar
>It denotes a folded block scalar
'Single quote surrounds a quoted flow scalar
"Double quote surrounds double quoted flow scalar
%It denotes the directive used

Example

%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"