Skip to content

YAML Failsafe Schema

Learn how YAML's failsafe schema works with its three core types: Generic Mapping (!!map), Generic Sequence (!!seq), and Generic String (!!str) and their JSON output representations.

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 Exampleyaml
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 Outputjson
{
	"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 Exampleyaml
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 Outputjson
{
	"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 Exampleyaml
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 Outputjson
{
  "Flow style": "String: just a theory.", 
  "Block style": "String: just a theory."
}
Navigation