YAML Sequences and Mappings Combinations
YAML Sequences and Mappings Combinations
Some examples of YAML sequences and mappings combined together:
1. Mapping to Sequences
attributes:
- attr1
- attr2
methods: [getter, setter]
Equivalent JSON
{
"attributes": ["attr1", "attr2"],
"methods": ["getter", "setter"]
}
2. Sequence-of-Mappings
friends:
- name: Tom Nolan
age: 23
- name: Ryan Raynolds
age: 45
-
name: Thomas Anderson
age: 28
Equivalent JSON
{
"friends": [
{"name": "Tom Nolan", "age": 23},
{"name": "Ryan Raynolds", "age": 45},
{"name": "Thomas Anderson", "age": 28}
]
}
3. Sequence-of-Sequences
my_sequences:
- [1, 2, 3]
- [4, 5, 6]
-
- 7
- 8
- 9
- 10
Equivalent JSON
{
"my_sequences": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 10]
]
}
4. Mapping-of-Mappings
Tom Nolan: {score: 65, avg: 0.278}
Ryan Raynolds: {
score: 63,
avg: 0.288
}
Equivalent JSON
{
"Tom Nolan": {
"score": 65,
"avg": 0.278
},
"Ryan Raynolds": {
"score": 63,
"avg": 0.288
}
}