YAML Cheat Sheet

In YAML

YAML, which stands for “YAML Ain’t Markup Language,” is a human-readable data serialization language that is often used for configuration files and data exchange between programming languages. It was first introduced in 2001 and has since become a popular choice for developers due to its simplicity and ease of use.

One of the main advantages of YAML is its readability. Unlike other data serialization formats, such as JSON or XML, YAML is designed to be easy for humans to read and write. This makes it a great choice for configuration files, where developers need to quickly and easily understand the settings and options being used.

Another advantage of YAML is its flexibility. It can be used to represent a wide range of data structures, including lists, dictionaries, and nested objects. This makes it a great choice for data exchange between different programming languages, as it can be easily parsed and understood by a variety of tools and libraries.

YAML is also highly customizable, with support for comments, anchors, and aliases. This allows developers to create complex data structures and reuse them throughout their codebase, making it easier to maintain and update their applications over time.

Basic Syntax

SyntaxDescription
key: valueA key-value pair separated by a colon.
- itemA list item, indicated by a hyphen.
# commentA comment, indicated by a hash symbol.

Data Types

TypeExampleDescription
String""hello""A sequence of characters.
Number42A numeric value.
Booleantrue or falseA logical value.
NullnullA value that represents nothing.
Array[1, 2, 3]A collection of values.
Object{ name: ""John"", age: 30 }A collection of key-value pairs.

Strings

SyntaxDescription
""hello""A double-quoted string.
'hello'A single-quoted string.
|A literal block scalar.
>A folded block scalar.
&An anchor.
*An alias.

Numbers

SyntaxDescription
42An integer.
3.14A floating-point number.
0b1010A binary number.
0o644An octal number.
0xFFA hexadecimal number.

Booleans and Null

SyntaxDescription
trueA boolean value that represents true.
falseA boolean value that represents false.
nullA value that represents nothing.

Arrays

SyntaxDescription
[1, 2, 3]An array of integers.
[""apple"", ""banana"", ""cherry""]An array of strings.
[true, false, null]An array of booleans and null.
- item1
- item2
- item3
An array of items.

Objects

SyntaxDescription
{ name: ""John"", age: 30 }An object with two key-value pairs.
{}An empty object.
key: value
key2: value2
An object with multiple key-value pairs.

Advanced Features

SyntaxDescription
!A tag.
<<A merge key.
&An anchor.
*An alias.
>A folded block scalar.
|A literal block scalar.

References

#