Difference between revisions of "YAML Syntax"

From Ever changing code
Jump to navigation Jump to search
Line 41: Line 41:
* hash tables
* hash tables
* kv pairs
* kv pairs
* collection (YAML specific term)
* collection (YAML specific term, that groups things indented at the same level)


{| class="wikitable"
{| class="wikitable"
Line 59: Line 59:
datacentre: { location: Poland, cabinet: 11 } </source>
datacentre: { location: Poland, cabinet: 11 } </source>
|}
|}
= Sequences =
Also known as:
* Lists, arrays or collections
* Denoted with a dash <tt>-</tt> and space
* Can be combined with mappings:
** mapping of sequences
** sequence of mapping
** list of maps
<source lang=yaml>
host: host-1    # sequence/list of mappings
  - datacenter:
    location: Poland
    cabinet: 11
roles:          # sequence
  - web
  - dns
  - ""  #blank lines are not allowed, thus double-quotes are required
#Flow style
<source lang=yaml>
roles: [ web, dns, "" ]
</source>

Revision as of 09:18, 6 August 2019

Styles

YAML syntax styles
Block style Flow style
Human frendly, less compact An extension of JSON, foldinf long lines, tags and anchors
host: host-1
datacenter:        #mapping
  location: Poland #key-value mapping indentention
  cabinet: 11
roles:             #list
  - web
  - dns
host: "host-1"
datacentrer: { location:
  Poland , cabinet: 11 }
roles: [ web , dns ] 
# {} kv mapping
# [] list (array)

Characters

  • Printable Unicode
  • Unsupported symbols
    • C0/C1 blocks
      • Exceptions: Tab, Line Feed, Carrage Return, Delete, Next line
    • Surrogates
  • Encoding: UTF-8, 16, 32
  • To be JSON compatibile must be UTF-32

Mappings

Mappings are also known as:

  • assosiative arrays
  • hash tables
  • kv pairs
  • collection (YAML specific term, that groups things indented at the same level)
Mappings, the colon-space combination that marks it as a mapping
Block style Flow style
host: host-1
datacenter:
  location: Poland
  cabinet: 11
# cabinet: 12   #the same keys are not allowed
host: host-1
datacentre: { location: Poland, cabinet: 11 }

Sequences

Also known as:

  • Lists, arrays or collections
  • Denoted with a dash - and space
  • Can be combined with mappings:
    • mapping of sequences
    • sequence of mapping
    • list of maps
host: host-1     # sequence/list of mappings
  - datacenter:
    location: Poland
    cabinet: 11
roles:           # sequence
  - web
  - dns
  - ""  #blank lines are not allowed, thus double-quotes are required

#Flow style
<source lang=yaml>
roles: [ web, dns, "" ]