Home » YAML Tutorial

YAML Tutorial

This tutorial provides basic and advanced concepts of YAML. Our YAML testing tutorial is designed for beginners and professionals. In this tutorial, we are going to learn how to write proper YAML. The aim of YAML is to create data about various hosts and our infrastructure. Our YAML tutorial includes all topics of YAML, such as what is YAML, YAML syntax, YAML data types, YAML styles in which the YAML program will be written, the mapping of key: value pairs, YAML structure.

What is YAML

  • YAML means yet another markup language. It is a data serialization language that works well with the modern programming language, and it is human-friendly.
  • It is used to define the data structures that are very easy to understand. These data structures are very easy to manage and maintain by the users.
  • YAML uses space to define something. If we use a single space or double space, it has different meanings in YAML. Spaces change the meaning of data structure.
  • YAML is case sensitive.
  • YAML is language independent. If we define the YAML once, the same YAML file can be invoked in Python file, Ruby, etc.
  • In the starting, YAML was very useful and friendly to people who work with data. YAML uses Unicode printable characters. In Unicode, some provide the information of structure, and others contain the data itself. Using the minimization of structural characters, a unique cleanness can be achieved by YAML. YAML is used to show the data itself in a meaningful and natural way. For example, bullet lists are created by dashes, key: value pairs are separated by a colon, and structure may be used by indentation.
  • In YAML, the data structure has myriad flavors. Using the three basic primitives, the data structure can be adequately represented. The basic primitives are mapping, sequences, and scalars. YAML leverages these primitives, and if we want to form a complete language for data serialization, it adds an easy typing system and aliasing mechanism. YAML is used by most of the programming languages for data serialization. But YAML excels in working with the languages that are built around the primitives like mapping, sequences, and scalars. These languages include the new wave of agile languages like Ruby, PHP, JavaScript, Python, and Perl.
  • To work well with the common use cases, YAML language was specialty designed. Common-use cases are cross-language data sharing, log files, debugging of complex data structure, interprocess messaging, object persistence, and configuration files. The programming becomes an easy task when data is easy to understand and view.

Format of Prolog

Consider the following text:

The YAML text of the above text is as follows:

In the string format, YAML takes the incentive. It generates the output as a reference previously.

Example 1:

In the following example, we will consider the accompanying point number of pi. The estimation number of pi is 3.1415926. In YAML, the drifting number is spoken as follows:

Example 2:

Consider the following human organs are to be stacked in explicit DS as follows:

When the above organs stack into YAML, all human organs are taken in a cluster data structure as a list. The following shows the output:

>>> yaml.load('''    - heart       - brain    - kidney    - lungs    - liver  ''')  ['heart' , 'brain' , 'kidney' , 'lungs' , ?liver?]  

Goals of YAML

The various goals of YAML are as follows:

  1. Human-readable: YAML is human readable. Humans can easily read it.
  2. Portable: YAML can work across multiple programming languages easily.
  3. Consistent: YAML is consistent, and it is able to support generic tools.
  4. Support various languages: YAML matches the native data structure of agile methodologies like PHP, JavaScript, Perl, Ruby, and Python.
  5. One-pass processing: when a programming language goes through the YAML file, it only needs to go through once to complete its task.
  6. Extensive and expressive: YAML is extensive, that means it should be easily readable by the human, and it is expressive.
  7. Easy Implementation: The implementation of YAML is easy and useful.

Prerequisite

Before learning YAML, you should have basic knowledge of basic computer functionality, basic mathematics, computer language, and logical operators.

Audience

Our YAML tutorial is designed for beginners and professionals.

Problems

We assure that you will not find any problem in this YAML Tutorial. But if there is any mistake, please post the problem in the contact form.


Next TopicYAML Syntax

You may also like