YAML

Basics

Released in 2001, data serialization language for humans, familiar to python, ruby, perl. Has scalars, lists, arrays, indentation, dashes, colons are data structures — used for config files and storing data

Human centric, portable, matching data structures to other languages, consistent and support generics. Support for a one pass processing. Expressive and extensible, easy to use.

Relies on:

  • spaces not tabs, indentation, dashes for lists, colons for key-values
host: hello88
  datacenter:
	  location: Adelaide
    veh: 12
  roles:
    - web
    - db

supports unicode, no C0/C1 blocks with exceptions. No surrogates, Encoding fro UTF-8 to 32(json compatible)

Styles

Block: not as compact, human friendly, common

host: hello88
  datacenter:
	  location: Adelaide
    veh: 12
  roles:
    - web
    - db

Flow: extension of JSON, folding, tags and anchors

host: "hello88"
datacenter: { location: 
  Adelaide, veh: 12 }
roles: [ web, db ]

Mappings

Associative arrays, hash tables, key values pairs, collections. User colon and space

Keys are unique, Can be nested. If flow style use bracket and commas. Example above.

Sequences

Lists, arrays. Marked as dash and space `- `, combine with mappings.  No blanks, no nested without mapping.

roles:
  - webserver
  - dbserver

roles: [ webserver, dbserver]

Scalars

string, number,  boolean

double quotes: allow escape sequences

mapping: assigns a scalar to another

host: hello88
datacenter:
	location: Perth
  veh: "12"
  veh_unit": '3'
	veh_u: 3
roles:
  - webserver
  - dbserver

multiline scalar:

event_time: |
	2011-11-11 - event1
  2011-11-13 - event2

folded style: make each new line into simple space

review: > 
  line number one
  line numero 2
  line lai 100101

Structure

Multi directives in one field, optional some platforms may not like. use --- to start a file

multidoc stream

---
host: hello88
datacenter:
	location: Perth
  veh: "12"
  veh_unit": '3'
	veh_u: 3
roles:
  - webserver
  - dbserver
---
host: hello99
datacenter:
	location: Auckland
  veh: "11"
  veh_unit": '2'
	veh_u: 2
roles:
  - webserver
  - cache

stream with end

uses triple dots to end, not closing data stream

---
host: hello88
datacenter:
	location: Perth
  veh: "12"

...
---
host: hello99
datacenter:
	location: Auckland
  veh: "11"
...

Comments

Use octothorpe and space  `# `, not in scalres are for humans, blank lines as commented lines.

# comment one
---
host: hello88
datacenter:
	location: Perth # Comment two
  veh: "12"

Tags

Used for custom URI, local tags, data types

# URI tag
%TAG ! tag:somedata:loc
---
# local tag
datacenter:
  location: !LOC Adelaide

#set a datatype
datacenter:
	location: Perth # Comment two
  veh: !!str 12
  veh_unit: !!str 2

Anchors

To reuse and store data, names can reused with & and reference anchor with *

# scalar anchor
datacenter:
  location: &ADL Adelaide

datacenter:
	location: *ADL

#collection anchor
---
roles: 
  &hosts
  - web
  - db 

roles: &hosts
  - web
  - db 

---
roles: *hosts

Use cases