Arrays / Lists
Todos los idiomas admiten las matrices o las listas.
TOML
fruits = [ "Apple", "Banana", "Strawberry" ]
formats = [
"YAML",
"JSON",
"TOML"
]
YAML
fruits:
- Apple
- Banana
- Strawberry
formats: [ YAML, JSON, TOML ]
JSON
{
"fruits": ["Apple","Banana","Strawberry"],
"formats": [
"YAML",
"JSON",
"TOML"
]
}
Para ampliar un poco estos ejemplos podemos crear una lista de Objetos / Tablas / Colecciones también así:
TOML
[[fruits]]
name = "Apple"
weight = 600
[[fruits]]
name = "Banana"
weight = 300
[[fruits]]
name = "Strawberry"
weight = 40
YAML
fruits:
- name: Apple
weight: 600
- name: Banana
weight: 300
- name: Strawberry
weight: 40
JSON
{
"fruits": [
{
"name" : "Apple",
"weight" : 600
},
{
"name" : "Banana",
"weight" : 300
},
{
"name" : "Strawberry",
"weight" : 40
}
]
}
Creo que ahora se entiende bastante bien cómo funcionan las matrices y las tablas; ampliémos un poco más para tener una visión completa.
TOML
[[fruits]]
name = "Apple"
weight = 600
[fruit.physical]
color = "red"
shape = "round"
[[fruit.variety]]
name = "red delicious"
[[fruit.variety]]
name = "granny smith"
[[fruits]]
name = "Banana"
weight = 300
[fruit.physical]
color = "yellow"
shape = "curved"
[[fruit.variety]]
name = "plantain"
[[fruits]]
name = "Strawberry"
weight = 40
[fruit.physical]
color = "red"
shape = "kind-of-oval"
[[fruit.variety]]
name = "the-good-one"
YAML
fruits:
- name: Apple
weight: 600
physical:
color: red
shape: round
variety:
- name: red delicious
- name: granny smith
- name: Banana
weight: 300
physical:
color: yellow
shape: curved
variety:
- name: plantain
- name: Strawberry
weight: 40
physical:
color: red
shape: kind-of-oval
variety:
- name: the-good-one
JSON
{
"fruits": [
{
"name" : "Apple",
"weight" : 600,
"physical": {
"color": "red",
"shape": "round"
},
"variety": [
{ "name": "red delicious" },
{ "name": "granny smith" }
]
},
{
"name" : "Banana",
"weight" : 300,
"physical": {
"color": "yellow",
"shape": "curved"
},
"variety": [
{ "name": "plantain" }
]
},
{
"name" : "Strawberry",
"weight" : 40,
"physical": {
"color": "red",
"shape": "kind-of-oval"
},
"variety": [
{ "name": "the-good-one" }
]
}
]
}