Table of Content

YAML Cheat Sheet

Links

Syntax Snippets

Scalars
# scalar = value
a: 1
a: 1.234
b: 'abc'
b: "abc"
b: abc
c: false	# boolean type
d: 2015-04-05	# date type

# Enforcing strings
b: !str 2015-04-05
Sequences
# sequence
array:
- 132
- 2.434
- 'abc'

# sqeuence of sequences
my_array:
- [1, 2, 3]
- [4, 5, 6]
Hashes
# Nest hash
my_hash:
  subkey:
    subsubkey1: 5
    subsubkey2: 6
  another:
    somethingelse: 'Important!'

# Hash of hashes
my_hash: {nr1: 5, nr2: 6}
HereDoc
# block notation (newlines become spaces)
content:
  Arbitrary free text
  over multiple lines stopping
  after indentation changes...

# literal style (newlines are preserved)
content: |
  Arbitrary free text
  over "multiple lines" stopping
  after indentation changes...

# + indicator (keep extra newlines after block)
content: |+
  Arbitrary free text with two newlines after


# - indicator (remove extra newlines after block)
content: |-
  Arbitrary free text without newlines after it


# folded style (folded newlines are preserved)
content: >
  Arbitrary free text
  over "multiple lines" stopping
  after indentation changes...

Multiple Documents
---
content: doc1
---
content: doc2
Reference Content
---
values:
- &ref Something to reuse
- *ref	# Reused content
Merging Keys
default_settings:
  install:
    dir: /usr/local
    owner: root
  config:
    enabled: false

# Derive settings for 'my_app' from default and change install::owner
my_app_settings:
  <<: *default_settings
  install:
    owner: my_user
Complex Mapping
---
? - key
:
  - value
# Note: key and value can be multiple, complex structures