Can I use TOML variables to nest TOML tables in other TOML tables?

3.2k views Asked by At

Can I put a TOML table into a TOML variable and then use that variable in another TOML table? I would like to replicate JSON ouput like this:

group1 = {
    "key1": "value1"
    "key2": "value2"
    "key3": {
        "key1": "value4"
        "key2": "value5"
        "key3": "value6"
    }
}

group2 = {
    "key1": "value1"
    "key2": "value2"
    "key3": {
        "key1": "value4"
        "key2": "value5"
        "key3": "value6"
    }
}

mainGroup = {
    "key1": "value1"
    "key2": "value2"
    "key3": group1
    "key4": {
        "key1": "value3"
        "key2": "value3"
        "key3": group2
    }
    "key5": {
        "key1": group1
        "key2": group2
    }
}
1

There are 1 answers

0
alex-dl On

Toml does not support references as Yaml does.

Readability and ease of implementation were some of the reasons for the developers of Toml to leave this out of the standard.

An interesting discussion about this topic can be read here:

https://github.com/toml-lang/toml/issues/77