adapted from this blog
# YAML
name: Jon
# YAML
object:
attributes:
- attr1
- attr2
- attr3
methods: [ getter, setter ]
parses to this json
{"object": {"attributes": ["attr1", "attr2", "attr3"], ...
# YAML
sonnet: |
I wish I could
write a poem
but I can"t
parses to:
{"sonnet": "I wish I could\nwrite a poem\nbut I can't\n"}
# YAML
---
document: this is doc 1
---
document: this is doc 2
...
name: SomeObject
attributes:
- attr1
- attr2
- attr3
methods: [ getter, setter ]
---
name: MyPrettyObject
attributes:
- attr1
- attr2
- attr3
methods: [ getter, setter ]
parses to:
{"attributes": ["attr1", "attr2", "attr3"],
"methods": ["getter", "setter"],
"name": "SomeObject"}
{"attributes": ["attr1", "attr2", "attr3"],
"methods": ["getter", "setter"],
"name": "MyPrettyObject"}
YAML also supports variables, or repeated nodes. The simplest explanation is that you define something as a variable by preceding it with "&NAME value" and you can refer to it with "*NAME" e.g.:
# YAML
some_thing: &NAME foobar
other_thing: *NAME
Parses to:
{"other_thing": "foobar", "some_thing": "foobar"}