I am trying to understand the TOML structure and
[[servers]]
ip = "10.0.0.1"
role = "frontend"
[[servers]]
ip = "10.0.0.2"
role = "backend"
developer = "developer_name"
If i parse the above the get the json as
{
"servers": [
{
"ip": "10.0.0.1",
"role": "frontend"
},
{
"developer": "developer_name",
"ip": "10.0.0.2",
"role": "backend"
}
]
}
As you can see the developer is nested into second object. But i need developer in the root.
I use this website to verify the TOML TOML Parser
expected result
{
"servers": [
{
"ip": "10.0.0.1",
"role": "frontend"
},
{
"ip": "10.0.0.2",
"role": "backend"
}
],
"developer": "developer_name"
}
Key/value pairs within Toml tables are not guaranteed to be in any specific order. The way to get 'developer' in the root table is to place it before the 'servers' array of tables:
developer = "developer_name"
[[servers]]
ip = "10.0.0.1"
role = "frontend"
[[servers]]
ip = "10.0.0.2"
role = "backend"
This will result in this Json structure:
{
"developer": "developer_name",
"servers": [
{
"ip": "10.0.0.1",
"role": "frontend"
},
{
"ip": "10.0.0.2",
"role": "backend"
}]
}
This small example could also be formatted with an inline array:
servers = [{ip = "10.0.0.1", role = "frontend"}, {ip = "10.0.0.2", role = "backend"}]
developer = "developer_name"
That would result in the same Json structure.