Search code examples
yamlpyyaml

Building an array of dictionary items in YAML?


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...

Solution

  • Use a dash to start a new list element:

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