YAML Cheat Sheet & Quick Reference - PDF
YAML Cheat Sheet & Quick Reference - PDF
YAML
This is a quick reference cheat sheet for understanding and writing YAML format configuration
files.
# Getting Started
- Introduction
YAML is a data serialisation language designed to be directly writable and readable by humans
Scalar types
n1: 1 # integer
n2: 1.234 # float
https://quickref.me/yaml 1/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
↓ Equivalent JSON
{
"n1": 1,
"n2": 1.234,
"s1": "abc",
"s2": "abc",
"s3": "abc",
"b": false,
"d": "2015-04-05"
}
Variables
↓ Equivalent JSON
{
"some_thing": "foobar",
"other_thing": "foobar"
}
Comments
Multiline strings
description: |
hello
world
↓ Equivalent JSON
{"description": "hello\nworld\n"}
Inheritance
https://quickref.me/yaml 2/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
parent: &defaults
a: 2
b: 3
child:
<<: *defaults
b: 4
↓ Equivalent JSON
{
"parent": {
"a": 2,
"b": 3
},
"child": {
"a": 2,
"b": 4
}
}
Reference
values: &ref
- Will be
- reused below
other_values:
i_am_ref: *ref
↓ Equivalent JSON
{
"values": [
"Will be",
"reused below"
],
"other_values": {
"i_am_ref": [
"Will be",
"reused below"
]
}
}
Folded strings
https://quickref.me/yaml 3/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
description: >
hello
world
↓ Equivalent JSON
Two Documents
---
document: this is doc 1
---
document: this is doc 2
# YAML Collections
Sequence
- Mark McGwire
- Sammy Sosa
- Ken Griffey
↓ Equivalent JSON
[
"Mark McGwire",
"Sammy Sosa",
"Ken Griffey"
]
Mapping
↓ Equivalent JSON
https://quickref.me/yaml 4/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
{
"hr": 65,
"avg": 0.278,
" bi"
Mapping to Sequences
attributes:
- a1
- a2
methods: [getter, setter]
↓ Equivalent JSON
{
"attributes": ["a1", "a2"],
"methods": ["getter", "setter"]
}
Sequence of Mappings
children:
- name: Jimmy Smith
age: 15
- name: Jimmy Smith
age: 15
-
name: Sammy Sosa
age: 12
↓ Equivalent JSON
{
"children": [
{"name": "Jimmy Smith", "age": 15},
{"name": "Jimmy Smith", "age": 15},
{"name": "Sammy Sosa", "age": 12}
]
}
Sequence of Sequences
my_sequences:
- [1, 2, 3]
- [4, 5, 6]
-
- 7
https://quickref.me/yaml 5/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
- 8
- 9
- 0
↓ Equivalent JSON
{
"my_sequences": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 0]
]
}
Mapping of Mappings
↓ Equivalent JSON
{
"Mark McGwire": {
"hr": 65,
"avg": 0.278
},
"Sammy Sosa": {
"hr": 63,
"avg": 0.288
}
}
Nested Collections
Jack:
id: 1
name: Franc
salary: 25000
hobby:
- a
- b
location: {country: "A", city: "A-A"}
↓ Equivalent JSON
https://quickref.me/yaml 6/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
{
"Jack": {
"id": 1,
"name": "Franc",
"salary": 25000,
"hobby": ["a", "b"],
"location": {
"country": "A", "city": "A-A"
}
}
}
Unordered Sets
set1: !!set
? one
? two
set2: !!set {'one', "two"}
↓ Equivalent JSON
{
"set1": {"one": null, "two": null},
"set2": {"one": null, "two": null}
}
Sets are represented as a Mapping where each key is associated with a null value
Ordered Mappings
ordered: !!omap
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffy: 58
↓ Equivalent JSON
{
"ordered": [
{"Mark McGwire": 65},
{"Sammy Sosa": 63},
{"Ken Griffy": 58}
]
}
https://quickref.me/yaml 7/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
# YAML Reference
Terms
Document indicators
% Directive indicator
Collection indicators
? Key indicator
: Value indicator
Alias indicators
* Alias indicator
Special keys
https://quickref.me/yaml 8/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
Scalar indicators
Misc indicators
- Escape Codes
Numeric
https://quickref.me/yaml 9/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
\U00102030 (32-bit)
Protective
\<TAB> (TAB)
\t (TAB) \v (VTAB)
Additional
\L (LS) \P (PS)
More types
# Also see
https://quickref.me/yaml 10/11
31/10/2023, 12:30 YAML Cheat Sheet & Quick Reference
Related Cheatsheet
Recent Cheatsheet
https://quickref.me/yaml 11/11