Skip to content
Manoj Kumar edited this page Feb 2, 2025 · 2 revisions

What is a YAML?

  • Ain't Markup Language
  • A strict superset of JSON
  • A human-friendly data serialization language for all programming languages.
  • A YAML file relies on whitespace and indentation to indicate nesting.
  • The number of spaces used for indentation doesn’t matter as long as they are consistent.
  • Tab characters cannot be used for indentation in YAML files; only spaces can be used.

Basic YAML syntax

A YAML format primarily uses three node types:

  1. Maps/Dictionaries (YAML calls it mapping)
    • The content of a mapping node is an unordered set of key/value node pairs, with the restriction that each of the keys is unique. YAML places no further restrictions on the nodes.
    • Maps in YAML files can be nested by increasing the indentation, or new maps can be created at the same level by resolving the previous one.
  2. Arrays/Lists (YAML calls them sequences)
    • The content of a sequence node is an ordered series of zero or more nodes. In particular, a sequence may contain the same node more than once. It could even contain itself.
    • Sequences in YAML are represented by using the hyphen (-) and space.
    • Can be embedded inside a map using indentation.
  3. Literals (Strings, numbers, boolean, etc.)
    • The content of a scalar node is an opaque datum that can be presented as a series of zero or more Unicode characters.

image

image

image

image

image

image

image

image

Normalized YAML

The YAML specification supports a number of features that you should probably never use, things that will not universally work across all parsers, will make your YAML non-portable to JSON, and will likely confuse people unfamiliar with these functions:

  • Anchors
  • References
  • Extensions

image

Using new YAML data types will not necessarily directly transfer to JSON parsers, including:

  • date/datetime
  • set
  • !!binary

https://spacelift.io/blog/yaml

Clone this wiki locally