Key-Value Pairs
In YAML, key-value pairs are defined using a colon followed by a space. For example:Arrays (Lists)
To define a list, start with a key and then list each item on a new line prefixed by a dash:Dictionaries (Maps)
Dictionaries group related properties under a single key. Below is an example that provides nutritional information for fruits:Practical Example: Representing a Car
Consider using a dictionary to represent a car and its properties such as color, model, transmission, and price. If you need additional details—like breaking the model into name and year—you can nest a dictionary within another dictionary:
- A dictionary is an unordered collection, which means the sequence of key-value pairs does not impact the data’s meaning. For example, the order of nutritional attributes for a fruit is irrelevant as long as the pairs are correct.
- In contrast, a list is always ordered. This means that the elements are processed in the sequence they appear.