Closed alexmozaidze closed 1 year ago
This isn't backwards-compatible: people may already have [root]
or root = ...
in their documents. This alone makes it a bit of a non-starter.
I also don't really like the proposal: it's not very obvious that "root" is something special, and as you mentioned it's not very useful for configuration files. If we really want to address this use case ("allow using an array at the top level") then there are probably better ways to do that, such as having [
as the first non-blank character:
[
1,
"val",
{k = "v"},
]
Or maybe something else. This is compatible, and much more "obvious".
But it's not at all clear that we really need to do anything here in the first place. It's probably best to first discus if we want to address this use case at all rather than specific solutions.
This issue, and ones adjacent to it, have come up quite a few times (though yours is much better-presented than most). In no particular order:
Perhaps reviewing those discussions (focusing on the general sentiments within), and rebutting them here, would help your case.
Personally I'm opposed to this sort of thing - the ordering and un-nameable nature of root w.r.t. the rest of the document is a strength in my eyes. The whole "replace JSON with TOML" argument actually does you a disservice IMO - they're two separate languages, intended for two different purposes, and I'm in no hurry to see a change there.
I came to the conclusion that adding root
would not only kill backwards compatibility, but also rob TOML of its simplicity. The only sane syntax for top-level arrays would be [ ... ]
, but that doesn't feel TOML.
Allowing to refer to the top-level object as
root
would allow users to define a top-level array. In other words, it would be possible to turn this JSON:Into the following TOML:
Without changing anything on the backend.
It would also allow to define top-level parameters explicitly:
Though, I would discourage doing so.
Possible problems
Simple, just error out. It doesn't make sense to have a value with 2 types at the same time.
Error out. Having parameters outside of any object implies
root
. So, basically, the above boils down toAnd redefining an object is not allowed.
Error out.
root
is reserved on top-level.Allowed, but discouraged.
Error out, since
root
is reserved on top-level.Perhaps, we could add the following syntax as an alternative?
How is this useful for configs?
Not much; configs don't need top-level arrays that often. This is mainly useful for when one uses TOML as a data file.
Summary
Introducing
root
as a special object poses some potential problems with readability if the user decides to mixroot
with normal syntax, but it allows to create an array as the top-level structure (which is the only real benefit), making it possible to fully replace JSON with TOML.