What is YAML?
YAML is a data serialization language that matches user’s expectations about data. It designed to be human friendly and works perfectly with other programming languages. It is useful to manage data and includes Unicode printable characters.
More in details:
- It is used to define data structures that are easy for users to understand, manage and maintain.
- YAML uses spaces to define something and to change the meaning of the data structure. The use of single or double spaces has a different meaning.
- YAML is case-sensitive.
- YAML is language independent. If we define the YAML once, the same YAML file can be used in Python, Ruby, etc.
- YAML uses Unicode printable characters. In Unicode, some characters provide structure information and others contain the data itself. By using minimization of structural characters, YAML can achieve a unique cleanliness. YAML is used to display the data itself in a meaningful and natural way.
- In YAML, the data structure has myriad flavors. Using the three basic primitives, the data structure can be represented adequately. The basic primitives are mapping, sequences, and scalars. YAML takes advantage of these primitives and, if we want to form a complete language for data serialization, it adds a simple typing system and an aliasing mechanism.
- The YAML language is designed to work well with common use cases like cross-language data sharing, log files, debugging of complex data structure, interprocess messaging, object persistence, and configuration files.
YAML was first proposed in 2001 and was developed by Clark Evans, Ingy döt Net, and Oren Ben-Kiki.
YAML was first said to mean “Yet Another Markup Language” to indicate its purpose as a markup language.
It was later repurposed as “YAML Aint Markup Language” to indicate its purpose as data-oriented.
Consider the text shown below:
Tutorial Reference provides tutorials, guides and references for developers
The YAML text of the above text is as follows:
>>yaml.load("Tutorial Reference provides tutorials, guides and references for developers")
>>'Tutorial Reference provides tutorials, guides and references for developers'
YAML takes the value in string format and represents the output as mentioned above.
Let's see some examples:
1. Number of Pi
Consider the following point number of “pi”, which has a value of 3.1415926.
2. Multiple values
Consider multiple values to be loaded into a specific data structure, as shown below
When you load this into YAML, the values are taken in an array data structure which is a form of list.
The output is as shown below:
['eggs', 'ham', 'spam', 'bread']
Goals of YAML
YAML includes a markup language with an important construct to distinguish data-oriented language from document markup.
The various goals of YAML are as follows:
- Human-readable: YAML is human readable.
- Portable: YAML can easily work with multiple programming languages.
- Consistent: YAML is consistent and it can support generic tools.
- One-pass processing: When a programming language examines the YAML file, it must do it only once to complete its task.
- Extensive and expressive: YAML is extensive, which means it should be easily human readable, and it is expressive.
- Easy Implementation: The implementation of YAML is simple and it is easy to use.