Building an array of dictionary items in YAML?

sadaf2605 picture sadaf2605 · May 13, 2015 · Viewed 50.2k times · Source

Basically trying to something in yaml that could be done using this json:

{
models:
 [
  { 
    model: "a"
    type: "x"
    #bunch of properties...
  },
  {
    model: "b"
    type: "y"
    #bunch of properties...
  }
 ]
}

So far this is what I have, it does not work because I am repeating my model key but what can be a proper way to do that by keeping that model key word?

models:
 model:
  type: "x"
  #bunch of properties...
 model:
  type: "y"
  #bunch of properties...

Answer

Charles Duffy picture Charles Duffy · May 13, 2015

Use a dash to start a new list element:

models:
 - model: "a"
   type: "x"
   #bunch of properties...
 - model: "b"
   type: "y"
   #bunch of properties...