YAML to JSON Cheatsheet

Yaml Cheatsheet

YAML Alt-tab guide

  • Yaml files begin with ---
  • Key value pairs are separated by colon
  • Lists begin with hypen
  • JSON uses {} brackets as separators while Yaml uses spaces or tabs similar to python
  • Spaces and tabs should not be mixed and quotes are not needed in most cases

Parent to child object

YAML

martin:
name: Martin D'vloper
job: Developer
skill: Elite

JSON

"martin": {
"name": "Martin D'vloper",
"job": "Developer",
"skill": "Elite"
}

Parent to child array

YAML

martin: 
- Martin D'vloper
- Developer
- Elite

JSON

"martin": [
"Martin D'vloper",
"Developer",
"Elite"
]

Parent to child array with object values

YAML

martin:
- name: Martin D'vloper
job: Developer
skill: Elite
- name: Martin D'plumber
job: Plumber
skill: noob

JSON

"martin": [
{
"name": "Martin D'vloper",
"job": "Developer",
"skill": "Elite"
},
{
"name": "Martin D'plumber",
"job": "Plumber",
"skill": "noob"
}
]

Parent to child array with a single value

YAML

martin: 
- name: Martin D'veloper
- name: Martin D'plumber

JSON

"martin": [
{
"name": "Martin D'veloper"
},
{
"name": "Martin D'plumber"
}
],

Parent to child array with mixed values

YAML

martin: 
- name : Martin D'veloper
- NoJob
- NoSkill
- name : Martin D'plumber
job : plumber
skill:

JSON

"martin": [
{
"name": "Martin D'veloper"
},
"NoJob",
"NoSkill",
{
"name": "Martin D'plumber",
"job": "plumber",
"skill": null
}
],

Key with null value

YAML

martin:

JSON

"martin": null

Empty string key

YAML

null:
null: test

JSON

"": null,
"": "test"

Nested complex

YAML

martin: 
skill:
- job: plumbing
level: noob
- job: development
level: elite
name:
firstname: Martin
realname: D'veloper
fakename: D'plumber
job:
- plumber
- developer

JSON

"martin": {
"skill": [
{
"job": "plumbing",
"level": "noob"
},
{
"job": "development",
"level": "elite"
}
],
"name": {
"firstname": "Martin",
"realname": "D'veloper",
"fakename": "D'plumber"
},
"job": [
"plumber",
"developer"
]
},