Yaml

From wikinotes

YAML is a superset of json, that layers on several additional featurs:

  • anchors/reference enable reused data
  • indentation based nested datastructures
  • comments
  • complex type storage (ex. ruby symbols, python bytestrings, ...)

Documentation

spec https://yaml.org/spec/

Anchors/Aliases

  • You can store/reuse reusable chunks of configuration within yaml
some_key: &variable_name
  a: 1
  b:
    - 1
    - 2

some_other_key: *variable_name
yet_another_key: *varaible_name

datatypes

String

See YAML documentation for block chomping indicator: https://yaml.org/spec/1.2/spec.html#id2794534

var: foo
var: "foo"

var: |
  keeps
  line breaks

var: >
  ignores
  line breaks,
  adds \n following string

var: >-
  ignores
  line breaks,
  no \n following string

# also supported
#
#  |   >
#  |+  >+
#  |-  >-

NoneType

var: Null

dict

a: 1
b: 2
##> {'a':1, 'b':2}
my_dict:
  a: 1
  b: 2
##> {'my_dict' : {'a':1, 'b':2}

list

## Both pythonic and YAML-like
## syntax is alright.
[ a, b, c, d ]

-
 a
 b
 c
 d

##> [ 'a','b','c','d' ]

list of dicts

-
  aaa: 1
  bbb: 2
-
  aaa: 1
  bbb: 2

##> [{aaa:1,bbb:2},{aaa:1,bbb:2}]