Essential YAML in under 5 Minutes

YAML is a widely used language and nowadays with advent of Kubernetes, becoming more popular.

This guide will give you a 5 minute quick walkthrough and an intro that can get you started with YAML.

To start with, Lets take a simple example: In a rainbow, there are 7 colors. we can represent this in yaml as a list

RainbowColors:
  - Voilet
  - Indigo
  - Blue
  - Green
  - Yellow
  - Orange
  - Red

Key-value pairs(dictionaries) are represented as key: value in YAML.

Now to a li'l advanced example:

Alice and Bob are 2 employees in the same firm, ABC Corp. Alice is 30 years old and Bob is 32. Alice works in sales department while Bob is in the technology dept.

If we want to put this information in excel, it would be something like

image.png

So, its a list of values that we want to represent with some key and values

ABCCorp:
  - Emp_Name: Alice
    Age: 30
    Department: sales
  - Emp_Name: Bob
    Age: 32
    Department: technology

There is another concept that a dictionary is unordered and a list is ordered.

Meaning that order doesn't matter in a dictionary for equality.

ABCCorp:
  - Emp_Name: Alice              
    Age: 30
    Department: sales

is same as

ABCCorp:
  - Emp_Name: Alice     
    Department: sales         
    Age: 30

But, In case of lists, order does matter.

RainbowColors:
  - Voilet
  - Indigo
  - Blue
  - Green
  - Yellow
  - Orange
  - Red

is not same as:

RainbowColors:
  - Voilet
  - Indigo
 - Yellow
  - Orange
  - Red
  - Blue
  - Green

Did you find this article valuable?

Support Manoj Chandrabhanu by becoming a sponsor. Any amount is appreciated!