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.
Unlock your potential: YAML basics series, all in one place!
To continue your exploration of YAML basics, check out our series of Answers below:
What is a YAML file?
Understand what YAML files are and the different styles they use.
What is block style in YAML?
Learn the block style format for structuring data in YAML.
What is flow style in YAML?
Discover how flow style differs from block style and when to use it.
How to represent different basic data types in YAML
Explore how YAML handles various basic data types, such as strings, integers, and booleans.
How to represent strings in YAML
Discover how YAML handles string values and different formatting options.
How to represent arrays in YAML
Explore how YAML represents arrays, with each element preceded by a hyphen (-
).
How to represent key-value pairs in YAML
Learn how to effectively represent key-value pairs within YAML syntax.
How to represent maps in YAML
Master how to structure key-value pairs as maps in YAML.
How to represent sequence in YAML?
Understand how to represent sequences in YAML files.
How to represent dictionaries in YAML
Explore how to represent complex data structures like dictionaries in YAML.
How to represent null values in YAML
Learn how to properly represent null or missing values in YAML.
How to write comments in YAML
Learn how to add comments in YAML to improve readability.
What are the advantages of using YAML over other data formats?
Understand why YAML is often preferred over JSON and XML for data serialization.