YAML Tutorial - A Complete Language Guide
YAML stands for YAML Ain't Markup Language
YAML was created in 2001. Data engineers need to work with YAML
Many important tools like Ansible and Docker
It is mostly used for configuration files and is seen as a much cleaner alternative to other traditional options like JSON & XML
YAML uses basic concepts of:
Keys: Value
YAML relies on Spacing & Indentation as a result, this approach gives a cleaner and consistent feel
YAML can be defined by
.yaml
extension or.yml
example<filename>.yml or <filename>.yaml
Example of YAML
team:
name: Manchester United
founded: 1878
stadium: Old Trafford
location: Manchester, England
leaders:
- position: Chairman
name: Joel Glazer Avram Glazer
- position: Manager
name: Erik ten Hag
notable_moments:
- year: 1958
event: Munich air disaster
description: |
Tragic plane crash that claimed the lives of several team members.
famous_players:
- Marcus Rashford
- Wayne Rooney
- Christiano Ronaldo
famous_players_2: [Marcus Rashford, Wayne Rooney, Christiano Ronaldo]
Compare YAML to JSON
{
"manchester_united": {
"name": "Manchester United",
"founded": 1878,
"stadium": "Old Trafford",
"location": "Manchester, England",
"leaders": [
{
"position": "Chairman",
"name": "Joel Glazer Avram Glazer"
},
{
"position": "Manager",
"name": "Erik ten Hag"
}
]
},
"notable_moments": [
{
"year": 1958,
"event": "Munich air disaster",
"description": "Tragic plane crash that claimed the lives of several team members.\n"
}
],
"famous_players": [
"Marcus Rashford",
"Wayne Rooney",
"Christiano Ronaldo"
],
"famous_players_2": [
"Marcus Rashford",
"Wayne Rooney",
"Christiano Ronaldo"
]
}
YAML to XML
<manchester_united>
<name>Manchester United</name>
<founded>1878</founded>
<stadium>Old Trafford</stadium>
<location>Manchester, England</location>
<leaders>
<position>Chairman</position>
<name>Joel Glazer Avram Glazer</name>
</leaders>
<leaders>
<position>Manager</position>
<name>Erik ten Hag</name>
</leaders>
</manchester_united>
<notable_moments>
<year>1958</year>
<event>Munich air disaster</event>
<description>Tragic plane crash that claimed the lives of several team members.</description>
</notable_moments>
<famous_players>Marcus Rashford</famous_players>
<famous_players>Wayne Rooney</famous_players>
<famous_players>Christiano Ronaldo</famous_players>
<famous_players_2>Marcus Rashford</famous_players_2>
<famous_players_2>Wayne Rooney</famous_players_2>
<famous_players_2>Christiano Ronaldo</famous_players_2>
In the next section, you will find amazing resources that will help you understand more about YAML
Resources to learn YAML
The YAML file explained
%[https://www.youtube.com/watch?v=fwLBfZFrLgI]
YAML and GitHub actions explained (YouTube)
%[https://www.youtube.com/watch?v=PwVUVkvcM5A&pp=ygUaaW50ZWdyYXRlIHlhbWwgd2l0aCBnaXRodWI%3D]
You can also delve into DevOps since you will mostly use YAML as a DevOps engineer
- 90DaysOfDevOps - I recommend this GitHub repo. It will give you better fundamental knowledge about DevOps, especially if you are a beginner
CONCLUSION
Comparing YAML to XML and JSON, we can see that:
YAML is human-readable and writable - its syntax is clean and simple, and indentation represents hierarchy which in turn reduces the need for complexity of symbols
YAML is easy to maintain - Slight changes can be made without touching the syntax
Data Serialization - easy exchange of data between different programs
It is concise - doesn't require unnecessary punctuation
Ease of Integration - commonly used in CI/CD pipelines
Version Control Friendly - can be used with VCS tools such as Git
Subscribe to my newsletter
Read articles from Preston Mayieka directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Preston Mayieka
Preston Mayieka
I enjoy solving technical problems, researching and developing new technologies, designing software applications for different platforms.