Skip to content

Clarify the reason empty keys are allowed#1095

Open
arp242 wants to merge 1 commit into
mainfrom
empty
Open

Clarify the reason empty keys are allowed#1095
arp242 wants to merge 1 commit into
mainfrom
empty

Conversation

@arp242

@arp242 arp242 commented Jun 29, 2026

Copy link
Copy Markdown
Member

TOML allows empty (quoted) keys:

"" = 123

Over the years I've seen a number of people express surprise that it's allowed.

The reason it's allowed is because TOML tables are intended to map to hash tables/dictionaries in programming languages, and they allow empty keys. So TOML does too.

You can still argue that it's a mistake to allow it in TOML, but we can't change that now and this at least clarifies the thinking behind why it's allowed.

@ChristianSi ChristianSi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may ultimately be better suited for a FAQ or rationale page, but since TOML does not yet have one, a short explanation in the spec itself seems appropriate enough. However, I’d be a bit more explicit about the underlying reasoning; see my suggested change.

Comment thread toml.md Outdated
You cannot use multi-line strings to define quoted keys.

TOML tables are intended to map to hash tables or dictionaries, as a consequence
empty quoted keys are allowed (though discouraged). A bare key must be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale feels a bit underspecified. Many languages and data structures that have hash tables or dictionaries also allow numbers, booleans, and other non-string values as keys, but TOML keys are intentionally more restricted than that. So, to prevent further possible confusion, I’d suggest making the rationale a bit more explicit, perhaps along these lines:

TOML tables are intended to map to hash tables or dictionaries, which commonly permit empty string keys. For that reason, empty quoted keys are allowed, though discouraged. A bare key must be non-empty.

@arp242 arp242 Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

TOML tables correspond to hash tables or dictionaries which usually permit any string value. For that reason empty quoted keys are allowed, though discouraged. A bare key must be non-empty.

"intended to map to" → "correspond to" as it seems a bit less of a mouthful.

"commonly permit empty string keys" → "usually permit any string value" as that's a bit more general.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arp242 Sure, sounds good!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, changed it with hash tables or dictionarieshash tables (also known as dictionaries) because on re-reading the "or" could be interpreted to mean "one or the other" rather than "also known as".

TOML allows empty (quoted) keys:

	"" = 123

Over the years I've seen a number of people express surprise that it's
allowed.

The reason it's allowed is because TOML tables are intended to map to
hash tables/dictionaries in programming languages, and they allow empty
keys. So TOML does too.

You can still argue that it's a mistake to allow it in TOML, but we
can't change that now and this at least clarifies the thinking behind
why it's allowed.
@cyyynthia

Copy link
Copy Markdown

This may ultimately be better suited for a FAQ or rationale page, but since TOML does not yet have one, a short explanation in the spec itself seems appropriate enough

I also agree that the rationale is purely informational and I have mixed feelings about it being part of the spec document. It's at the same time valuable info, and at the same time noise that doesn't really have normative value. Perhaps a <details> block would be the best of both worlds? 🤔

@ChristianSi

Copy link
Copy Markdown
Contributor

@cyyynthia: For just one sentence added, a <details> block seems overkill, though.

@arp242

arp242 commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Personally I think the "why" of these sort of things should be part of the main specification text. Over the years I've found that knowing why something is the way it is hugely helps actually understanding and remembering things. Otherwise it just become rote memorisation and I kind of suck at that.

Within reason, of course. A potential FAQ could expand on some of the things in the specification. But I do think it's helpful to explain the why, when it might be useful, as concise as possible, regardless of whether we have a FAQ or not.

I would certainly not be in favour of footnotes or <detail> tags. I avoid that in my own writing and generally dislike it as everyone reads them anyway and they give a disjointed reading experience. The exception being Sir Terry's footnotes because they're just so funny (I'd be okay with footnotes if they're sufficiently entertaining).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants