There are some rules that YAML has in place to avoid issues related to ambiguity in relation to various languages and editing programs. These rules make it possible for a single YAML file to be interpreted consistently, regardless of which application and/or library is being used to interpret it.
- YAML files should end in .yaml whenever possible.
- YAML is case sensitive.
- YAML does not allow the use of tabs. Spaces are used instead as tabs are not universally supported.
Basic Data Types
Scalars are a pretty basic concept. They are the strings and numbers that make up the data on the page. A scalar could be a boolean property, like Yes, integer (number) such as 5, or a string of text, like a sentence or the title of your website.
Scalars are often called variables in programming. If you were making a list of types of animals, they would be the names given to those animals.
Most scalars are unquoted, but if you are typing a string that uses punctuation and other elements that can be confused with YAML syntax (dashes, colons, etc.) you may want to quote this data using single ‘ or double " quotation marks. Double quotation marks allow you to use escapings to represent ASCII and Unicode characters.
Here is a simple sequence, It is a basic list with each item in the list placed in its own line with an opening dash.
This sequence places each item in the list at the same level. If you want to create a nested sequence with items and sub-items, you can do so by placing a single space before each dash in the sub-items. YAML uses spaces, NOT tabs, for indentation. You can see an example of this below.
If you wish to nest your sequences even deeper, you just need to add more levels.
Sequences can be added to other data structure types, such as mappings or scalars.
Mapping gives you the ability to list keys with values. This is useful in cases where you are assigning a name or a property to a specific element.
This example maps the value of pets to the animal key. When used in conjunction with a sequence, you can see that you are starting to build a list of pets. In the following example, the dash used to label each item counts as indentation, making the line items the child and the mapping line animal: pets the parent.
Resources and Further Documentation
For more information about YAML, including detailed documentation about how it works, check out the resources linked below.