YAML Dictionaries

All items in a YAML document are members of at least one dictionary. A dictionary represents the key:  value form (the colon must be followed by spaces). YAML represents dictionaries with indentation, colons and dashes.

YAML Dictionary Example

   name:  Donna Fermentation
   job:  Microbiologist
   skill:  Elite

If we did not put  invalid syntax, the output will turn out like the example below.

Dictionary output:

object {1}
  donna {3}
    name : Donna Fermentation
    job : Microbiologist
    skill : Elite

We can also create more complex dictionaries, such as a list of dictionaries, dictionaries whose values are lists, or a mix of both. Every new list element has to be started by a dash (-). 

Complex Dictionaries Example

-  donna
      job:  Microbiologist
      name:  Donna Frmntation
       -  pgpr
       -  pcr
       -  optimization
-  akubaru
      job:  Microbiologist
      name:  Akubaru Yum
      -  yeast
      -  mechanic
      -  fermentation

Complex dictionary output:

object {2}
donna {3}
        job : Microbiologist
        name : Donna Frmntation
        skill [3]
            0 : pcr
            1 : pgpr
            2 : optimization
akubaru {3}
        job : Microbiologist
        name : Akubaru Yum
        skill [3]
            0 : yeast
            1 : mechanic
            2 : fermentation

We can also abbreviate the dictionary using the flow collections (in valid JSON style).

Flow Collections Example

[name:  ‘Donna Frmntation’,  job:  ‘Microbiologist’,  skill:  ‘Elite’]
donna: [name:  ‘Donna Frmntation’,  job:  ‘Microbiologist’,  skills:  ‘pgpr’ ‘pcr’ ‘optimization’]

Next up

Once you’ve built an understanding of YAML dictionaries, check out the Scalars page.

%d bloggers like this: