Ferenc Almasi
June 25, 2021
How to write a YAML file
1min read

YAML means "Yet Another Markup Language" in version 1.0, and became "YAML Ain't Markup Language" in 1.1 . Created in 2001 by Clark Evans, it was meant to be more elaborate than CSV and as simply written, (or even more), than XML.


The key to master YAML is to be very accurate when it comes to indentation. Here the indentation acts as a structure for the file.


Just like JSON, YAML works with a Key-value pair system :

Strings

Putting your strings between quotes is not necessary, unless you want to do multiple-lines.

last-name: Doe
first-name: 'John'

Multiple-lines takes two forms, one which doesn't keep the format :

bar: >
Once upon a time, there was
a beautiful princess
named Snow White.

is interpreted as :

bar: Once upon a time, there was a beautiful princess named Snow White.

And one which keeps the format as is :

bar: |
Once upon a time, there was
a beautiful princess
named Snow White

will be interpreted as :

bar : Once upon a time, there was
a beautiful princess
named Snow White

Numbers

integer: 506
negative-integer: -374
float: 103.98

Nulls

foo: null
bar: ~

Booleans

day: true
night: false

Comments

# List of users
name: 'John Doe' # A user

Objects

planets: { Mars: 'terrestrial planet', Jupiter: 'gas giant' }

Arrays

cities: ["Reykjavik", "Kuala Lumpur"]
# or
cities:
- "Paris"
- "New York"

you can make multiple-lines arrays :

groceries:
  - fruits:
      apples: 3
      bananas: 1
  - other:
      - milk: semi-skimmed

About

About the author

Ludivine Achouri

Passionate web developer from France


Comments


Copyright © Achouri Ludivine 2022 | All rights reserved