What is YAML in 5 minutes

What is YAML in 5 minutes

YAML is a data serialization language that has a simple syntax and allows you to store complex data in a compact and readable format. Here’s how it comes in handy for DevOps and virtualization.

What is YAML?
YAML vs JSON vs XML
Salient features of YAML
YAML syntax
What else can YAML do?

What is YAML?

YAML is a language for storing information in a human-readable format. Its name stands for Another Markup Language. However, later the transcript was changed to – “YAML is not a markup language” to distinguish it from real markup languages.

The language is similar to XML and JSON, but uses a more minimal syntax while maintaining similar capabilities. YAML is commonly used to create configuration files in Infrastructure as Code (Iac) programs, or to manage containers in DevOps.

Most often, YAML is used to create automation protocols that can execute sequences of commands written in a YAML file. This allows your system to be more independent and responsive without additional developer attention.

More and more companies are adopting DevOps and virtualization, so YAML is a must have for the modern developer. In addition, YAML is easy to integrate thanks to support for Python (using the PyYAML library, Docker, or Ansible) and other popular technologies.
YAML vs JSON vs XML
YAML (.yml)

Features of YAML:

human-readable code;
minimalistic syntax;
tailored for working with data;
inline style similar to JSON (YAML is a superset of it);
supports comments;
supports unquoted strings;
considered "cleaner" than JSON;
additional features (extensible data types, relative anchors and type mapping with preservation of key order).

Application: YAML is best suited for data-intensive applications that use DevOps pipelines or virtual machines. In addition, improving the readability of data comes in handy in teams where developers interact with them frequently.
Json

Features of JSON:

harder to read;
explicit, strict syntax requirements;
inline style similar to YAML (some YAML parsers can read JSON files);
no comments yet;
strings need double quotes.

Usage: JSON is used in web development – it is the best format for serializing and transferring data over an HTTP connection.
XML

Features of XML:

harder to read;
more verbose;
acts as a markup language and YAML as a language for formatting data;
more features than YAML, such as tag attributes;
more rigid document schema;

Application: XML is ideal for complex projects that require fine control over validation, schema, and namespace. The language is poorly readable, requires more bandwidth and storage, but provides unprecedented control.
Salient features of YAML
Support for multi-documents

You can combine multiple YAML documents into one YAML file for easier file organization and data parsing.

Documents are separated by three hyphens (-):


player: playerOne

action: attack (miss)

player: playerTwo

action: attack (hit)

Comment support

YAML allows you to add comments after the # symbol, like in Python:

key: # This is a one-line comment

  • value line 5
    #It
    # multiline comment
  • value line 13

Easy-to-read syntax

The syntax for YAML files uses the Python-like indentation system. You must use spaces, not tabs, to avoid confusion.

This gets rid of the extra characters that are in JSON and XML (quotes, brackets, curly braces).

As a result, the readability of the file is significantly improved.
YAML

Imaro:
author: Charles R. Saunders
language: English
publication-year: 1981
pages: 224

Json

{
“Imaro”: {
“author”: “Charles R. Saunders”,
“language”: “English”,
“publication-year”: “1981”,
“pages”: 224,
}
}

Explicit versus implicit typing

YAML offers both auto-type detection and the ability to explicitly specify the data type. To use a specific type, you must write !! [type] in front of the value.

This is an int value:

is-an-int: !! int 14.10

Convert any value to a string:

is-a-str: !! str 67.43

The value must be boolean:

is-a-bool: !! bool yes

Lack of executable files

YAML does not contain executable files. Therefore, it is safe to exchange YAML files with a third party.

To use executables, YAML needs to be integrated with other languages ​​such as Perl or Java.
YAML syntax

The language has a few basic concepts that handle most of the data.
Key-value pairs

Most of the data in a YAML file is stored as a key-value pair, where key is the name of the pair and value is the associated data.
Scalars and mapping

A scalar is a single value that corresponds to a name.

You may also like

The Role of AI in Personalizing User Experience Across Digital Platforms

The Role of AI in Personalizing User Experience Across Digital Platforms

In the ever-evolving landscape of the digital age, the intersection of technology and personal preference has given rise to a...

Cybersecurity in Modern Vehicles: Ensuring Safety in the Digital Age

Cybersecurity in Modern Vehicles: Ensuring Safety in the Digital Age

The integration of digital technology into automotive design has transformed the humble automobile into a nexus of connectivity and innovation....

The Thrills of High Stakes: Inside the World of High Roller Online Casinos

The Thrills of High Stakes: Inside the World of High Roller Online Casinos

When it comes to the world of online casinos, there’s a niche that takes the experience to a whole new...

All the Essentials of Business Plan for a Startup 

All the Essentials of Business Plan for a Startup 

Today, it is difficult to imagine a successful startup that does not have a business plan including all the details....

Back to Top