Skip to content

Instantly share code, notes, and snippets.

@davidlares
Last active March 17, 2025 19:18
Show Gist options
  • Save davidlares/7b6ecf91a241b6851777a10c446c556b to your computer and use it in GitHub Desktop.
Save davidlares/7b6ecf91a241b6851777a10c446c556b to your computer and use it in GitHub Desktop.
A basic YAML syntax review concept and implementation.

A basic YAML syntax review concepts

In a short note, YAML files represent configuration data in most of the times. According to Wikipedia: YAML "is a human-friendly data serialization standard for all programming languages". Basically we can say that is similar to XML and JSON notation and it is pretty used on DevOps activities for IaC configurations and for sharing data across multiple applications.

Features

  1. key-Value Pair: there's nothing more to say to this. You have a "Key" that acts as an Identification for value itself.

    Here's an example:

    Key: Value

  2. Array and Lists: is the same data structure, just like any programming language.

    Here's an example:

    Fruits:

    - Apple

    - Orange

    - Banana

  3. Dictionaries and Maps: it is a common data structure equivalent to a hash map

    Here's an example:

    Fruits:

    Cal : 104

    For this structure is very important the usage of blank spaces for hierarchy purposes (indentation)

    A typical dictionary example is a Car with multiple internal properties represented by Key-Value pair representation, but a Parking lot example is represented by a couple of dictionaries.

Final Notes

  1. Properties can be defined without any order
  2. For arrays, item order matter
  3. In case of having two dictionaries, they will be considered the same if their properties are equal without an order
  4. The # is for comments
# Dictionary
Employee:
# Key/Pair Value
Name: Jacob
Sex: Male
Age: 30
Title: Systems Engineer
#Array
Projects:
- Automation
- Support
# Array of Dictionaries
Payslips:
- Month: June
Wage: 4000
- Month: July
Wage: 4500
- Month: August
Wage: 4000
@victorclee
Copy link

victorclee commented Mar 17, 2025

Thank you for this useful summary! @davidlares and @f2ka07 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment