A brief introduction to YAML
Tags: devops, softwaredevelopment, configuration, yaml
Published: 2021-05-03 06:46:33

---
title: A brief introduction to YAML
published: true
date: 2021-05-03 06:27:10 UTC
tags: devops,softwaredevelopment,configuration,yaml
canonical_url: https://dvirsegal.medium.com/are-we-all-yaml-engineers-now-48ec170d7180
---

![](https://cdn-images-1.medium.com/max/1024/0*yLW7GHOOakdTxUQA)<figcaption>Photo by <a href="https://unsplash.com/@louishansel?utm_source=medium&amp;utm_medium=referral">Louis Hansel</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

#### What is YAML? And how it works?

Recently I switched jobs, and as part of this change, I’ve been introduced to a whole new tech stack. RabbitMQ 🐰, Java Spring, Docker, etc. (meaning more subjects to write about 😂). Most of the technologies I use on a daily basis consume YAML as their configuration. In this post, I’ll try to illustrate what I’ve learned (and from where) while trying to understand this new world.

![](https://cdn-images-1.medium.com/max/430/0*_as2PgoE1whljRRq.jpg)<figcaption>Learn the YAML way — <a href="https://www.memecreator.org/meme/hey-kid-wanna-format-some-yaml/">src</a>.</figcaption>

#### It is what it is 🤨

YAML stands for **Y** AML **A** in’t **M** arkup **L** anguage, originally named Yet Another Markup Language. The name was chosen because it requires much less markup than other traditional languages, such as XML. It distinguishes it as more data-oriented rather than markup-oriented. [YAML spec](https://yaml.org/spec/) says it better:

> YAML™ (rhymes with “camel”) is a human-friendly, cross language, Unicode based data serialization language designed around the common native data structures of agile programming languages.

#### Well, what is it used for? 😒

It has become widespread for writing configuration files because it uses a human-readable, intuitive, and flexible language. It can be used with almost any application that needs to send or store data (and has no code execution capabilities — Secure?). YAML is a superset of JSON, which means any valid JSON is a valid YAML file. It has several advantages over JSON; it can self-reference, support complex datatypes, embedded block literals, support comments, [and more](https://www.json2yaml.com/yaml-vs-json).

![](https://cdn-images-1.medium.com/max/1024/1*r4xnH5tf3qKh4kRZPtXPZQ.png)<figcaption>JSON VS YAML</figcaption>

Furthermore, I’ve recently learned that one of the most common usages for YAML in the java world is an autogenerated code using [swagger](https://swagger.io/docs/specification/2-0/what-is-swagger/) (API deployment). YAML defines the classes, and swagger generates the code. But that is a separate story for a different post.

### How does it work? 💪🏻

The basic building block of YAML documents is a key-value pair. The nesting is based on indentation (similar to Python), making it resistant to delimiter collision. Just keep in mind, whatever you do, DO NOT USE TABS. Yaml hates tabs, and it won’t work. Tip: use a YAML linter, whether an [online](http://www.yamllint.com/) one or a [plugin](https://plugins.jetbrains.com/plugin/15349-yamllint) in your [IDE](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml).

![](https://cdn-images-1.medium.com/max/1024/0*_ZJk9J6azqXo0riC.jpg)<figcaption>Writing YAML — <a href="https://i.redd.it/0lg04ovga0m11.jpg">src</a></figcaption>

It is insensitive to quotes and brackets, making special characters more easily defined, especially for strings. To better explain the above concepts, you can find below some simple examples, which I found essential to know when starting to use YAML:

Variables are defined using a **colon** and  **space** :

```
integer: 17 
string: "17" 
float: 17.0 
boolean: Yes
```

A list or array can be defined using an **inline** format that’s similar to JSON or a conventional **block**  format:

```
--- # To Do List in Block Format 

- Homework 
- Walk with the dog 
- Dog should eat homework  

--- # To Do List in Inline Format 

[Homework, Walk with the dog, Dog should eat homework]
```

You can denote a string with a | symbol, which keeps **newlines** , or a > symbol, which **folds**  them:

```
data: |    
Each of these    
Newlines    
Will be broken up  

data: >    
This text is    
wrapped and will    
be formed into    
a single paragraph
```

![](https://cdn-images-1.medium.com/max/474/0*dnEcv2X56KOBGGew)<figcaption>Do you want to know more? -<a href="http://4.bp.blogspot.com/-erLVwTj3cA4/UaFHnIiBFYI/AAAAAAAAYBQ/NQzrb7iyDiM/s1600/1+starship+troopers+2.jpg">src</a></figcaption>

The YAML complete documentation can be found on its [official site](https://yaml.org/spec/1.2/spec.html). It is worth going over to be familiar with it. Also, there are plenty of online tutorials; I’ve found this one to be a great source:

{% youtube 1uFVr15xDGg %}

#### To Wrap Up 🌯

YAML is a data-oriented language and a superset of JSON that comes with multiple built-in advantages. It became an industry standard for configuration files. But overall, it is human-readable, which makes it easy to use and maintain. Just be gentle with these whitespaces.

![](https://cdn-images-1.medium.com/max/400/0*2Eqc7HVTmNMiqP2-.jpg)<figcaption>YAML -<a href="https://memegenerator.net/instance/52839223/i-know-kung-fu-i-know-yaml">src</a></figcaption>