Skip to content

YAML Nested Sequences

Learn how to create and use nested sequences in YAML to represent hierarchical data structures with arrays inside arrays or objects.

YAML Nested Sequences

A YAML nested sequence is a sequence contained within another sequence.

For example:

person: 
  - 
    name: Luke
    hobbies: 
      - sports
      - music  
  - 
    name: Ryan
    hobbies: 
      - movies
      - cooking
  - 
    name: Thomas
    hobbies: 
      - tennis
      - swimming

Another more complex example:

example:
  id: 1
  name: Tom
  salary: 20000
  hobby:
    - Computer programming
    - Tennis
  location: {country: "Italy", city: "Rome"}
Equivalent JSONjson
{
  "example": {
    "id": 1,
    "name": "Tom",
    "salary": 20000,
    "hobby": ["Computer programming", "Tennis"],
    "location": {
        "country": "Italy", "city": "Rome"
    }
  }
}
Navigation