Cheatsheet: YAML

Basic syntax

Scalars: Scalars are simple values such as strings, numbers, and booleans.

name: John Doe
age: 30
is_active: true

Lists: Lists are sequences of scalars or other lists, represented by a dash - followed by a space and the value.

fruits:
  - apple
  - banana
  - cherry

Maps (or dictionaries): Maps are collections of key-value pairs, represented by a colon : and an indented value.

person:
  name: John Doe
  age: 30
  is_active: true

Strings: Strings can be defined with double quotes " or single quotes '. Multi-line strings can be defined with the > or | indicator.

message: "Hello, World!"
poem: |
  Roses are red,
  Violets are blue,
  Sugar is sweet,
  And so are you.

Comments: Comments start with the # symbol and continue to the end of the line.

# This is a comment
name: John Doe

Anchors and Aliases: Anchors allow you to reuse parts of the configuration, and Aliases allow you to refer to these reusable parts.

# Anchor
person: &person_id
  name: John Doe
  age: 30
  is_active: true
# Alias
person_copy: *person_id