Example YAML File with Explanations

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

The below is an example of a YAML file with some explanations provided.   Note that it is called “YAML” (as opposed to YML).  YAML stands for “YAML Ain’t Markup Language” — kind of a recursive acronym.  But it was known as “Yet Another Markup Language” earlier in its development. The file extension is typically “.yml”.

example yaml file

example yaml file

Line 1: A YAML directive starts with % and this %YAML directive indicates the version

Line 3: Comments starts with # and can start anywhere in the line

Line 19 and Line 4:  The asterisk with an arbitrary id is a reference to an anchor of the same id.  Anchor indicated by ampersand (The word anchor and ampersand both starts with the letter “a” — that’s how you remember it).

List items are denoted with hyphens on separate lines.  Or it can be in inline format with items comma-separated and the list bounded by square brackets.

Key-value data always have key and value separated by colon.  The key-value pairs can be in separate lines or comma-separated and whole set within curly braces.

Comma and colons used in separation must be followed by a space.

Types are auto-detected.  That is why you don’t have to quote strings, unless they are ambiguous.  In that case, you can disambiguate them with single or double quotes or explicit typing with the !!str prefix.

The single exclamation prefix denotes user-defined local data types.

Line 2:  three hyphens indicates the start of document.

Line 34: optional dot-dot-dot indicates end of document.

Learn more about YAML on official site and Wikipedia.