YAML stands for YAML Ain’t Markup Language. YAML is a data serialization format similar to XML and JSON. However, it is more human-readable.
YAML is a case-sensitive data format. It uses spaces (
) to define document structure. Tabs (\t
) are not allowed in YAML.
Usually, YAML files are used to store configuration data and are commonly named with either .yml
or .yaml
extensions, e.g., config.yml.
A YAML file contains a stream of data that may contain multiple documents.
Different documents are separated using three dashes (---
).
If you want to mark the end of a document without starting a new one, you may use three dots (...
). Let’s look at the example below to understand this better.
---
# list of markup languages
Formats:
- XML: eXtensible Markup Language,
- JSON: JavaScript Object Notation,
- CSV: Comma-separated Values
---
# list of encodings
Encodings:
- Unicode
- ASCII
- UTF8
---
# list of programming languages
Language:
- Java
- C++
- Python
...
The above style where hyphens (-
) and spaces (
) are used to specify a list of items is known as Block Style.
We can also represent the above document in a more compact notation known as Flow Style. It uses inline JSON to represent lists and key-value pairs. This makes YAML a superset of JSON.
Below is the same document represented using Flow Style notation.
---
# list of markup languages
Formats: [{ "XML": "eXtensible Markup Language"}, {
"JSON": "JavaScript Object Notation" }, {"CSV": "Comma-separated Values"}]
---
# list of encodings
Encodings: [ Unicode, ASCII, UTF8]
---
# list of programming
Languages: [Java, C++, Ruby]
...
Learn more about the syntax, data types, and various key concepts related to the YAML language through this mini-course: Introduction to YAML.