What is YAML?

Feb 14

What is YAML?

YAML (YAML Ain't Markup Language) is a human-readable data format used for configuration files, automation scripts, and data exchange.

Basic Concepts of YAML

Key-Value Pairs
YAML stores data as key-value pairs, similar to JSON or dictionaries.

Example:
name: John Doe
  age: 30
  city: Bangkok

Keys: name, age, city
Values: "John Doe", 30, "Bangkok"

Indentation Instead of Braces
YAML uses spaces for indentation instead of {} or [].

Example:
person:
    name: John Doe
    age: 30
    address:
    city: Bangkok
    country: Thailand


Use spaces, NOT tabs!

Lists (Arrays)
Lists are created using dashes (-).

Example:
fruits:
    - Apple
    - Banana
    - Mango

Equivalent in JSON:
{ "fruits": ["Apple", "Banana", "Mango"] }


Lists can also contain objects:

employees:
  - name: Alice
    age: 28
  - name: Bob
    age: 35


Data Types
YAML supports various data types:

string_value: "Hello, YAML!"
integer_value: 25
float_value: 99.9
boolean_value: true
null_value: null


Multi-line Strings
Use | for preserved formatting:

description: |
    This is a multi-line text.
    The formatting is preserved.

 
Use > for folded (single-line) text:

summary: >
    This is a multi-line text.
    But it will be converted into a single line.


Equivalent: "This is a multi-line text. But it will be converted into a single line."

Comments
Use # for comments:
#This is a comment
app_name: MyApp # Inline comment
Created with