YAML Syntax - YAML tutorial

Grammar rules:

  • Case Sensitive
  • Use indentation to represent a hierarchy
  • Tabs are not allowed when indenting, only spaces are allowed.
  • The number of indented spaces is not important, as long as the same level of elements is left-justified

All YAML files can optionally begin with  and end with This is part of the YAML format and indicates the start and end of a document.



value:

value

A value named “key”:

key: value

A list:

- 1- true- 'a string'

Alternate list syntax (Flow style):

[1, true, "a string"]

A list named “list”:

list:  - 1  - true  - 'a string'

Alternate list syntax (Flow style):

list: [1, true, 'a string']

A dictionary:

key1: val1key2: val2key3: val3

Dictionary in Flow style:

{key1: val1, key2: val2, key3: val3}

A dictionary named “dictionary”:

dictionary:  key1: val1  key2: val2  key3: val3

Dictionary in Flow style:

dictionary: {key1: val1, key2: val2, key3: val3}

A list of dictionaries:

cartoon:    -   name: Tom        age: 15    -   name: Jerry        age 12

A list of dictionaries in Flow style:

cartoon: - {name: Tom, age: 15} - {name: Jerry, age: 12}

OR

cartoon: [{name: Tom, age: 15}, {name: Jerry, age: 12}]

This is same as JSON. Because YAML is the superset of JSON