Introduction to YAML

Selvam Raju
3 min readMar 19, 2023

--

In this blog, you will learn about YAML and benefits of YAML.

What Is YAML?

YAML stands for YAML Ain’t Markup Language.

  • YAML is a very simple, text-based, human-readable language used to exchange data between people and computers.
  • YAML is a digestible data serialization language often used to create configuration files with any programming language.
  • YAML is not a programming language. It is mostly used for storing configuration information.
  • YAML files store data, and they do not include commands and instructions.
  • YAML is a data serialization language similar to XML or JSON. However, it is much more human readable and concise.

Where is YAML used?

  • Any data structure that can be described using the XML or JSON formats may be represented using YAML.
  • Any textual data in Unicode format, such as configuration or log files, can be stored and managed via YAML. As a result, it can store, transfer, and share data across a wide range of hardware and software platforms. Understanding this format is crucial because any modifications to configuration files may result in erroneous operation of your programme.

YAML is used in configuration files, log files, object persistence, caching, and messaging (sending information across various software components or applications).

How To Write YAML

The basic structure of a YAML file is a map. You might call this a dictionary, hash or object, depending on your programming language or mood.

Very generally, it’s keys and values all the way down:

key: value

YAML Example: Collection Types

All you have to do to create collections is Use Indentation:

environment:
TEST_REPORTS: /tmp/test-reports

If you have a list of things (like images), you can denote that sequence using dashes:

docker:
- image: ubuntu:14.04
- image: mongo:2.6.8
command: [mongod, --smallfiles]
- image: postgres:9.4.1

Note that the second item in the sequence has two keys: image and command. The command key uses a JSON-style sequence because (remember!) YAML is a superset of JSON.

Finally, YAML doesn’t allow tab characters, so if you’re using those to indent, have your text editor convert those to spaces.

Benefits of YAML:

The following traits apply to YAML:

  • Human-readable — YAML is very much readable by humans. It enables the representation of intricate data structures in a comprehensible way. This is demonstrated by the fact that even the home page of the official YAML website (https://yaml.org) is presented as a YAML document.
  • Simple and clean syntax- YAML is simple to read and straightforward to understand. It can express a large range of diverse data structures with ease.
  • Easy to implement and use — It is easy to implement and use.
  • Version control friendly — Since YAML only saves plain text, it may easily be added to a version control system like a Git or Subversion repository.
  • Consistent data model to support generic tools. It has powerful tools, such as PyYAML.
  • Fast — YAML is fast to load and easy to process in memory.
  • Secure — Many security issues in programming languages are related to parsing untrusted input (such as JSON). Python, Ruby, Java, JavaScript, PHP, and more make it possible for attackers to exploit these vulnerabilities bypassing unexpected input strings to the parser. YAML is designed to prevent these types of exploits by specifying what type of data each part of the YAML stream must consist of.

Also read this tutorial YAML Tutorial: A Complete Language Guide with Examples for basic syntax types, and how YAML is different from JSON. It also covers advanced YAML syntax types and usage examples for Ansible and Kubernetes.

👉 Follow me Selvam R and Cloudnloud Tech Community on LinkedIn for more insightful knowledge & resources

--

--