Purpose of YAML
YAML stands for “YAML Ain’t Markup Language”.
It’s a human-friendly way to describe structured data (like lists, settings, or nested configurations). Think of it as a clean alternative to JSON or XML.
It’s mostly used for:
- Configuration files (Docker Compose, Kubernetes, GitHub Actions, Ansible, etc.)
- Data serialization (storing and exchanging structured data)
- Readability first → YAML’s main selling point is that it’s easier for humans to write and read than JSON/XML.
The idea: Represent data hierarchically
YAML is just about describing data structures in text.
For example, this YAML:
person:
name: Alice
age: 30
hobbies:
- hiking
- cooking
- paintingis equivalent to this JSON:
{
"person": {
"name": "Alice",
"age": 30,
"hobbies": ["hiking", "cooking", "painting"]
}
}Both represent the same data structure. YAML just uses indentation instead of curly braces and brackets.
How to think about YAML
Don’t think of YAML as a programming language—it’s not.
Think of it like a way of writing down nested dictionaries, lists, and values in a way that humans can read and machines can parse.
So the “idea behind YAML” is simply: A human-friendly text format to represent structured data (like JSON), most often used in configuration files.
YAML as a recipe book
Imagine you’re writing down a recipe. A recipe has ingredients, steps, and maybe some notes. That’s basically what YAML is: a structured list of information.
Example in YAML:
recipe:
name: Pancakes
servings: 4
ingredients:
- flour: 2 cups
- milk: 1.5 cups
- eggs: 2
- sugar: 2 tbsp
steps:
- Mix dry ingredients.
- Add milk and eggs, whisk until smooth.
- Cook on skillet until golden brown.This looks natural—like a recipe card. But a computer can also parse this into structured data it understands.
YAML as a family tree
YAML is also like drawing a family tree with indentation:
family:
parents:
- name: John
age: 45
- name: Mary
age: 42
children:
- name: Alice
age: 12
- name: Bob
age: 9Indentation shows who belongs to who (parents and children are under “family”).
YAML as a folder structure
You can also think of YAML like folders on your computer:
project/
├─ name: MyApp
├─ version: 1.0
├─ dependencies/
│ ├─ flask: 2.2
│ └─ requests: 2.28
└─ settings/
├─ debug: true
└─ port: 8080It’s basically like describing nested folders and files, but in text.
Analogy summary:
- Recipe book → shows how YAML organizes steps & ingredients (lists & mappings).
- Family tree → shows how indentation expresses hierarchy.
- Folder structure → shows how it maps nested data clearly.
Basics
#Yaml is just key:value. When you want to better understand a yaml file
#draw a Tree Diagram, or ask chatGPT to do it for you.
## strings
city: Sofia
team : "Levski"
##intiger
year_founded: 1914
##boolean
is_current_champion: false
is_it_blue: on
is_it_red: off
### multiline strings
#### everything will be interpreted on one line
background: >
Founded in 1914 and it is
probably the best team in the country
#### maintain the new lines. It will treat new lines as new lines.
organization_history: |
Founded in 1914 and is
probably the best tean in the country
This will be interpreted as you see it here
## Sequnces/Lists -> Just add a dash - or brackets [].
## NB: Think of them like arrays in other languages.
famous_players:
- Georgi Asparuhov
- Hristo Iliev
- Pavel Panov
famous_players_2: [Georgi Ivanov, Nasko Sirakov]
## Mappings/Dictionary -> Just Key–value pairs.
managment_staff:
president: Ivailo Petkov
head_coach: Julio Velazquez
## Complex types
famous_players_3:
- name: Daniel Borimirov
number: 5
- name: Elin Topuzakov
number: 4
#### sequence of mappings
people:
- name: Alice
age: 30
- name: Bob
age: 25
#### Mapping of sequences:
menu:
breakfast:
- eggs
- bacon
lunch:
- sandwich
- salad
#### Docker Compose examples
services → mapping
ports → sequence
environment → mapping
volumes → sequence or mapping depending on contexHacks from Everyday Struggles
How to indent multiple lines at once in VS Code:
- Select(mark) multiple lines
Indent to the right -> Tab
Indent to the left -> Shift + Tab