Skip to content

YAML

Links: 300 home


Basics

name: Joe
age: 35
{
    "name": "Joe",
    "age": 35
}


names:
    - name 1
    - name 2
    - name 3
{
    "names": ["name 1", "name 2", "name 3"]
}

Objects of Objects

name: Joe
age: 35
address:
  streetAddress: 123 No Street
  city: Phantom City
{
    "name": "Joe",
    "age": 35,
    "address": {
        "streetAddress": "123 No Street",
        "city": "Phantom City"
    }
}

You leave an empty space after : if you want to nest objects within objects

person:
 details: 
  name: Fred
  age: 34
{
  "person": {
    "details": {
      "name": "Fred",
      "age": 34
    }
  }
}

Array of Objects

person:
 - name: Fred
   age: 45
 - name: Albert
   age: 16
{
  "person": [
    {
      "name": "Fred",
      "age": 45
    },
    {
      "name": "Albert",
      "age": 16
    }
  ]
}

- is followed by a : hence that value becomes an object inside the array

person:
 - name: Fred
 - name: Albert
 - name: Jay
   age: 45
 - names: Last
 - nothing
{
  "person": [
    {
      "name": "Fred"
    },
    {
      "name": "Albert"
    },
    {
      "name": "Jay",
      "age": 45
    },
    {
      "names": "Last"
    },
    "nothing"
  ]
}

In the above example last entry doesn't have : after it so its just an entry in the array and not an object.

Miscellaneous

input: value
# the above is same as
input:
    value

Last updated: 2022-05-27