Search code examples
toml

TOML multi-level table syntax inside array -- illegal or not


I'm seeing an error during parsing with the Python and JS parsers. I can't seem to find an example in the TOML repo about whether this should be accepted or not:

[[somearray]]
one.two = false # fails, '.' not allowed in key

I know I can express this as:

[[somearray]]
   [somearray.one]
   two = false # OK

The TOML readme offers this example (among others):

[fruit]
apple.color = "red"
apple.taste.sweet = true

which does not involve arrays but seems to legitimize this syntax.

I also observe that a plain file with this content:

apple.color = "red"

is rejected. In conclusion, until you enter "table mode" (so to say) with an actual bracketed table, keys can only be singles.

Now again, in the TOML readme it says (although in the tables section):

"Dotted keys define everything to the left of each dot as a table."

Obviously, if mainstream parsers choke on it, it's not a good idea to use it, but I'd like to understand if/why it's a known no-no. Is here some ambiguity I'm not seeing?


Solution

  • These cases are confirmed valid TOML, per the 1.0 spec, which adds many more examples: https://github.com/toml-lang/toml/blob/1.0.0/toml.md