What is YAML?
YAML stands for YAML Ain't Markup Language. It is a data format used to exchange data. YAML is often used for writing configuration files. It is similar to XML and JSON files. In YAML, you can store data.
Serialization
YAML is a data serialization language. So, what is data serialization? Serialization converts the data objects into a stream of bytes. These are can be stored into the database. Other popular data serialization languages include XML, JSON, BSON, MessagePack, and protobuf.
Advantages of YAML
YAML can easily be converted to JSON, XML.
Most languages uses YAML.
YAML is simple and easy to read.
It has a strict system. (Indentation is important)
It is most powerful when representing complex data.
Basic Data Representation
Key Value Pair
Data can be represented using key value pair. A key has a value assigned to it which is separated by ":". For example, "jujutsu kaisen" :"It is an anime". Here the key "jujutsu kaisen" has the value "It is an anime".
List
List is the representation of data in a sequential order. For example, list of countries can be represented as:
-India
-China
-USA
A key that has multiple values as list can be represented as a block in YAML.
An example is,
fruits: -apple -mango -banana
Dictionaries
A key has key value pairs as its value is seen in dictionaries.
For example,
Banana: Calories: 105 Fat: 0.4g Carbs: 27g
Key notes to be noted while working with YAML files
Indentation is very important in YAML files.
You can differentiate documents in a YAML files using "---".
All documents in a YAML file can be ended using "...".
An important difference between a dictionary and a list is that dictionaries are unordered whereas list are ordered.
Comments are followed by "#".