This is a quick reference cheat sheet for understanding and writing YAML format configuration files.
YAML is a data serialisation language designed to be directly writable and readable by humans
n1: 1 # integer
n2: 1.234 # float
s1: 'abc' # string
s2: "abc" # string
s3: abc # string
b: false # boolean type
d: 2015-04-05 # date type
{
"n1": 1,
"n2": 1.234,
"s1": "abc",
"s2": "abc",
"s3": "abc",
"b": false,
"d": "2015-04-05"
}
Use spaces to indent. There must be space between the element parts.
some_thing: &VAR_NAME foobar
other_thing: *VAR_NAME
{
"some_thing": "foobar",
"other_thing": "foobar"
}
object:
attributes:
- a1
- a2
- a3
methods: [getter, setter]
{
"object": {
"attributes": ["a1", "a2", "a3"],
"methods": ["getter", "setter"]
}
}
# A single line comment example
# block level comment example
# comment line 1
# comment line 2
# comment line 3
jack:
id: 1
name: Franc
salary: 5000
hobby:
- a
- b
loc: {country: "A", city: "A-A"}
{
"jack": {
"id": 1,
"name": "Franc",
"salary": 5000,
"hobby": ["a", "b"],
"loc": {
"country": "A", "city": "A-A"
}
}
}
Employee:
id: 1
name: "Franc"
department:
name: "Sales"
depid: "11"
{
"Employee": {
"id": 1,
"name": "Franc",
"department": {
"name": "Sales",
"depid": "11"
}
}
}
children:
- name: Jimmy Smith
age: 15
- name: Jenny Smith
age: 12
{
"children": [
{"name": "Jimmy Smith", "age": 15},
{"name": "Jenny Smith", "age": 12}
]
}
set1: !!set
? one
? two
set2: !!set {'one', "two"}
{
"set1": {"one": null, "two": null},
"set2": {"one": null, "two": null}
}
parent: &defaults
a: 2
b: 3
child:
<<: *defaults
b: 4
{
"parent": {"a": 2, "b": 3},
"child": {"a": 2, "b": 4}
}
values: &ref
- These values
- will be reused below
other_values:
i_am_ref: *ref
{
"values": [
"These values",
"will be reused below"
],
"other_values": {
"i_am_ref": [
"These values",
"will be reused below"
]
}
}
---
document: this is doc 1
---
document: this is doc 2
...