yaml example
Example 1: create child for yml elements
items: [ 1, 2, 3, 4, 5 ]
names: [ "one", "two", "three", "four" ]
Example 2: yaml understanding
---
key: value
another_key: Another value goes here.
a_number_value: 100
scientific_notation: 1e+12
boolean: true
null_value: null
key with spaces: value
however: 'A string, enclosed in quotes.'
'Keys can be quoted too.': "Useful if you want to put a ':' in your key."
single quotes: 'have ''one'' escape pattern'
double quotes: "have many: \", \0, \t, \u263A, \x0d\x0a == \r\n, and more."
# UTF-8/16/32 characters need to be encoded
Superscript two: \u00B2
# Multiple-line strings can be written either as a 'literal block' (using |),
# or a 'folded block' (using '>').
literal_block: |
This entire block of text will be the value of the 'literal_block' key,
with line breaks being preserved.
The literal continues until de-dented, and the leading indentation is
stripped.
Any lines that are 'more-indented' keep the rest of their indentation -
these lines will be indented by 4 spaces.
folded_style: >
This entire block of text will be the value of 'folded_style', but this
time, all newlines will be replaced with a single space.
Blank lines, like above, are converted to a newline character.
'More-indented' lines keep their newlines, too -
this text will appear over two lines.
####################
# COLLECTION TYPES #
####################
# Nesting uses indentation. 2 space indent is preferred (but not required).
a_nested_map:
key: value
another_key: Another Value
another_nested_map:
hello: hello
# Maps don't have to have string keys.
0.25: a float key
? |
This is a key
that has multiple lines
: and this is its value
? - Manchester United
- Real Madrid
: [2001-01-01, 2002-02-02]
a_sequence:
- Item 1
- Item 2
- 0.5
- Item 4
- key: value
another_key: another_value
-
- This is a sequence
- inside another sequence
- - - Nested sequence indicators
- can be collapsed
json_map: {"key": "value"}
json_seq: [3, 2, 1, "takeoff"]
and quotes are optional: {key: [3, 2, 1, takeoff]}
anchored_content: &anchor_name This string will appear as the value of two keys.
other_anchor: *anchor_name
base: &base
name: Everyone has same name
foo:
<<: *base
age: 10
bar:
<<: *base
age: 20
explicit_string: !!str 0.5
python_complex_number: !!python/complex 1+2j
? !!python/tuple [5, 7]
: Fifty Seven
datetime: 2001-12-15T02:59:43.1Z
datetime_with_spaces: 2001-12-14 21:59:43.10 -5
date: 2002-12-14
gif_file: !!binary |
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
set:
? item1
? item2
? item3
or: {item1, item2, item3}
set2:
item1: null
item2: null
item3: null
...
Example 3: yaml syntax multiple values
martin:
name: Martin D'vloper
job: Developer
skill: Elite
Example 4: yaml key value pairs
first_name: Bilbo
last_name: Baggins
age_years: 111
home: Bag End, Hobbiton