Search code examples
toml

Does TOML support top level arrays of dictionaries?


I am trying to write a configuration file that would be an array (list) or dictionaries (hashes, tables). In JSON terms that would be for instance

[
   {
      "a":1,
      "b":2
   },
   {
      "a":10,
      "b":20
   }
]

I was hoping that

[[]]
a = 1
b = 2

[[]]
a = 10
b = 20

would be correct, but it is rejected by my Go parser with

 unexpected token "]]", was expecting a table array key

This suggests that only top-level dictionaries (hashes, tables) are allowed. Is that really the case?


Solution

  • TOML 1.0.0 does not permit a top level array.

    From github.com/toml-lang/toml:

    TOML always has a hash table at the top level of the file, which can easily have data nested inside its keys, but it doesn't permit top-level arrays or floats, so it cannot directly serialize some data.