Exploring the structure of a YAML file
Let’s look at the three main components of a YAML file:
- Nodes
- Maps
- Sequences
Let’s start with the node.
The YAML node
The main object of a YAML file is a so-called node. A node represents the data structure below it, which can be a scalar value, a map, or a sequence.
We use this snippet of a configuration file as an example:
database-config:
type: mysql
Both database-config
and type
are YAML nodes. While the database-config
node holds a map containing the key type
and the value mysql
, the node type just has the scalar value mysql
in it.
The YAML map
A YAML map contains between zero and an arbitrary number of key/value pairs. Plus, there is an interesting correlation between nodes and maps: the key and the value may be another node, creating the hierarchy in the file.
Let’s extend the configuration snippet from the node section before:
database-config:...