Skip to main content

YAML Failsafe Schema

YAML Failsafe Schema

A YAML schema is defined as a set of tags and includes a mechanism for resolving non-specific tags.

The failsafe schema in YAML was created so that it can be used with any YAML document.

It is also considered a recommended schema for a generic YAML document.

There are three types of failsafe schema:

  • Generic Mapping
  • Generic Sequence
  • Generic String

Generic Mapping

It represents an associative container.

Each key is unique in the association and mapped to exactly one value. YAML includes no restrictions for key definitions.

It is represented with !!map tag.

The following is an example of a representation of a generic mapping:

Generic Mapping Example
Tom: Nolan
Ryan : reynolds
Clark : Kent
Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }

The output of the generic mapping structure in JSON format is shown below:

Generic Mapping JSON Output
{
"Ryan": "reynolds",
"Flow style": {
"Oren": "Ben-Kiki",
"Ingy": "d\u00f6t Net",
"Clark": "Evans"
},
"Clark": "Kent",
"Tom": "Nolan"
}

Generic Sequence

It represents a type of sequence.

It includes a collection indexed by sequential integers starting with zero.

It is represented with !!seq tag.

The following is an example of a representation of a generic sequence:

Generic Sequence Example
Tom: Nolan
Ryan : reynolds
Clark : Kent
Flow style: !!map [ Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki ]

The output of the generic sequence structure in JSON format is shown below:

Generic Sequence JSON Output
{
"Ryan": "reynolds",
"Flow style": [
{
"Clark": "Evans"
},
{
"Ingy": "d\u00f6t Net"
},
{
"Oren": "Ben-Kiki"
}
],
"Clark": "Kent",
"Tom": "Nolan"
}

Generic String

It represents a unicode string.

It includes a collection indexed by sequential integers starting with zero.

It is represented with !!str tag.

The following is an example of a representation of a generic string:

Generic String Example
Block style: !!str |-
String: just a theory.

Flow style: !!str "String: just a theory."

The output of the generic string in JSON format is shown below:

Generic String JSON Output
{
"Flow style": "String: just a theory.",
"Block style": "String: just a theory."
}