Basic Knowledge of YAML

YAML – Basics

YAML Syntax: The syntax of YAML consists of different objects and structures. Objects refer to meaningful pieces of information, while structures dictate how these objects are arranged in a file, such as ordered lists, unordered lists, dictionaries, etc. Here are some common YAML syntax elements:

Objects: In YAML, objects are called "dictionaries," presented in the form of key-value pairs:

key: value

In the example above, key is the dictionary key, and value is the corresponding value.

Lists: Lists in YAML are categorized as ordered lists and unordered lists. Ordered lists are indicated by hyphens, with each item on a new line:

- item1
- item2
- item3

Unordered lists are represented with asterisks:

* item1
* item2
* item3

Multiline Strings: Multiline strings in YAML refer to strings that span multiple lines. In YAML, you can represent them using either the pipe symbol or the greater-than symbol. The pipe symbol preserves line breaks, while the greater-than symbol collapses multiple lines into one:

description: |
  This is
  a multiline
  string.

message: >
  This is a
  long message.

In the example above, description is a string separated by the pipe symbol, while message is a string separated by the greater-than symbol.

Comments: Comments provide a way to add remarks in YAML and start with a hash symbol:

# This is a comment
key: value

Conclusion: YAML is a human-readable data serialization format widely used in programming for its simplicity and readability.

Last updated