TOML 03 📄 Basic Keys, Dotted Keys, and Quoted Keys
TOML keys are the identifiers on the left side of an assignment. They come in three forms—bare, quoted, and dotted—and the form determines which characters are allowed, whether the key creates nested tables, and how the key interacts with table headers. A bare key is the common case: letters, digits, underscores, and hyphens. A quoted key exists for strings that bare keys cannot express: spaces, Unicode, or characters that would otherwise be structural. A dotted key is a sequence of bare or quoted keys joined by dots, and it creates a table for every segment before the last one.
This chapter covers the three key forms, the character rules for each, the table-creation side effect of dotted keys, and the restrictions that prevent a dotted key from colliding with a table header. The sections that follow walk through bare keys and their limits, quoted keys and when to use them, and dotted keys with the composition rules that determine valid nesting.
Key point: A bare key allows only ASCII letters, digits, underscores, and hyphens; a quoted key allows any string; a dotted key creates and defines a table for each segment before the last, and those tables cannot later be opened with a [table] header.
Why key forms exist
The character restriction problem. TOML’s bare keys are deliberately narrow. The specification allows only A-Za-z0-9_-, which covers the majority of configuration keys but excludes spaces, dots, Unicode, and punctuation . A key like character encoding or ʎǝʞ cannot be written bare. Quoted keys exist to fill that gap: they follow the same rules as TOML strings, so any character that can appear in a string can appear in a quoted key .
The structural ambiguity problem. A dot in a bare key would be indistinguishable from the dot that creates nesting. TOML resolves this by prohibiting dots in bare keys and defining dots as structural separators. A key written as fruit.apple.color means three nested tables, not one key with two dots in its name . When the dot is meant literally—as in a domain name or a version string—the segment must be quoted: site."google.com" = true creates a key named google.com inside site, not a table named google containing a table named com .
The redefinition problem. Dotted keys define tables implicitly. Writing fruit.apple.color = "red" creates the table fruit and the table fruit.apple. The specification states that since tables cannot be defined more than once, redefining those implicit tables with a [table] header is invalid . The rule prevents contradictory definitions: a table created by a dotted key and a table opened by a header would have no clear merge semantics. The exception is that a [table] header can define a sub-table within a table created by dotted keys, as long as that sub-table has not itself been created .
a. Bare keys and their character limits
A bare key is written without quotes and may contain only ASCII letters, ASCII digits, underscores, and dashes. It must be non-empty. The ABNF for an unquoted key is 1*( ALPHA / DIGIT / %x2D / %x5F ), which is one or more characters from that set .
# Valid bare keys
name = "app"
port = 8080
max_retries = 3
api-key = "secret"
2fast = true
# INVALID: spaces, dots, and Unicode are not allowed in bare keys
# first name = "Ana"
# user.name = "Ana" (this is a dotted key, not a bare key with a dot)
# ключ = "value"
A bare key consisting entirely of digits is technically valid, but the specification discourages it because a dotted key like 3.14159 parses as a table named 3 containing a key named 14159, not as a floating-point key . The practical advice is to quote any key that looks like a number, or to avoid all-digit keys entirely.
b. Quoted keys and the string rules
A quoted key uses the same syntax as a TOML string: basic strings with double quotes and escape sequences, or literal strings with single quotes and no escape processing . Multi-line strings are not allowed as keys; the key must fit on one line .
# Basic quoted key: escape sequences processed
"key with spaces" = "value"
"character encoding" = "utf-8"
# Literal quoted key: backslashes literal
'C:\Users\name' = "path"
# Quoted key containing a quote
'quoted "value"' = "also valid"
# Quoted segment inside a dotted key
site."google.com" = true
The specification recommends bare keys whenever possible and quoted keys only when necessary . The recommendation is about readability: quoted keys are harder to scan, and the quoting signals that the key is unusual. A key with a space or a dot in it is a sign that the configuration might benefit from a different structure, but when the structure is fixed by an external system, quoting is the correct escape hatch.
c. Dotted keys and implicit table creation
A dotted key is a sequence of simple keys—each bare or quoted—joined by dots. Whitespace around the dots is ignored, though the specification recommends avoiding extraneous whitespace . Each segment before the last creates a table if one does not already exist; the last segment is the key that receives the value.
# Dotted key creates fruit and fruit.apple
fruit.apple.color = "red"
# The parsed structure:
# { fruit: { apple: { color: "red" } } }
# Multiple dotted keys share the implicit tables
fruit.apple.taste.sweet = true
# fruit and fruit.apple already exist; fruit.apple.taste is created
# Quoted segments in a dotted key
name.first = "Arthur"
"name".'last' = "Dent"
The restriction is that the tables created by dotted keys cannot be reopened with a header. The following is invalid because [fruit.apple] attempts to redefine a table that the dotted key already created :
# INVALID: fruit.apple was created by the dotted key
[fruit]
apple.color = "red"
[fruit.apple] # error: table already defined
The [table] form can, however, define a sub-table within a table created by dotted keys, provided that sub-table has not itself been created. The official example shows [fruit.apple.texture] as valid after fruit.apple.color and fruit.apple.taste.sweet, because texture is a new table inside fruit.apple .
# VALID: texture is a new sub-table of fruit.apple
[fruit]
apple.color = "red"
apple.taste.sweet = true
[fruit.apple.texture]
smooth = true
Complete Example Session
# ============================================
# PART 1: BARE KEYS
# ============================================
name = "my-app"
port = 8080
max_retries = 3
api-key = "secret"
# ============================================
# PART 2: QUOTED KEYS
# ============================================
"key with spaces" = "value"
'literal\path' = "C:\\temp"
"unicode key ʞ" = "value"
# ============================================
# PART 3: DOTTED KEYS CREATE TABLES
# ============================================
fruit.apple.color = "red"
fruit.apple.taste.sweet = true
# Parsed: { fruit: { apple: { color: "red",
# taste: { sweet: true } } } }
# ============================================
# PART 4: QUOTED SEGMENT IN A DOTTED KEY
# ============================================
site."google.com" = true
# Parsed: { site: { "google.com": true } }
# ============================================
# PART 5: VALID TABLE HEADER AFTER DOTTED KEYS
# ============================================
[fruit.apple.texture]
smooth = true
# texture is a new sub-table; fruit and fruit.apple were
# created by dotted keys and are not redefined
# ============================================
# PART 6: INVALID REDEFINITION (COMMENTED)
# ============================================
# [fruit.apple] # INVALID: already created by dotted key
# [fruit] # INVALID: already created by dotted key
The parts covered bare keys, quoted keys with literal and basic styles, dotted keys creating nested tables, a quoted segment inside a dotted key, a valid sub-table header, and the redefinition that the specification prohibits.
Quick Reference
Key Forms
| Form | Syntax | Allowed Characters |
|---|---|---|
| Bare | name = value | A-Za-z0-9_- |
| Basic quoted | "key" = value | Any string, escapes processed |
| Literal quoted | 'key' = value | Any string, backslashes literal |
| Dotted | a.b.c = value | Sequence of bare/quoted keys |
Dotted Key Rules
| Rule | Detail |
|---|---|
| Table creation | Each segment before last creates a table |
| Redefinition | Cannot open a dotted-key table with [table] |
| Sub-tables | [parent.child] valid if child is new |
| Whitespace | Ignored around dots, but discouraged |
| Quoted segments | Allow dots and special characters in a segment |
Valid and Invalid Patterns
| Pattern | Validity |
|---|---|
fruit.apple.color = "red" | Valid |
[fruit.apple] after above | Invalid |
[fruit.apple.texture] after above | Valid (new sub-table) |
site."google.com" = true | Valid (quoted segment) |
3.14159 = "pi" | Discouraged (parses as nested) |
Best Practices
✅ Do This:
# Use bare keys for simple identifiers
name = "app"
port = 8080 # ✅
# Quote keys with spaces or special characters
"character encoding" = "utf-8" # ✅
# Quote segments containing dots
site."google.com" = true # ✅
# Group dotted keys together under one parent
fruit.apple.color = "red"
fruit.apple.taste = "sweet" # ✅
❌ Don’t Do This:
# Spaces in bare keys
first name = "Ana" # ❌
# Unquoted dot in a key segment
site.google.com = true # creates 3 tables, not 1 key # ❌
# Open a dotted-key table with a header
fruit.apple.color = "red"
[fruit.apple] # ❌
# All-digit dotted key that looks like a float
3.14159 = "pi" # ❌ (parses as nested)
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Key with space fails to parse | Bare keys exclude spaces | Quote the key |
| Dot creates unexpected nesting | Dots are structural | Quote the segment: "a.b" |
| Table redefinition error | Dotted key already created it | Define all keys in one place |
| Numeric key parsed as table | 3.14 means 3 → 14 | Quote the key |
| Unicode bare key rejected | Bare keys are ASCII-only | Quote the key |
Real-World Examples
1. Bare key with hyphen
api-key = "secret"
2. Quoted key with space
"character encoding" = "utf-8"
3. Literal quoted key
'C:\path' = "windows"
4. Dotted key creating tables
fruit.apple.color = "red"
5. Quoted segment in dotted key
site."google.com" = true
6. Valid sub-table header
[fruit.apple.texture]
smooth = true
7. Multiple dotted keys under one parent
fruit.apple.color = "red"
fruit.apple.taste = "sweet"
8. Quoted dotted key segment
"name".first = "Arthur"
9. Bare key with underscore
max_retries = 3
10. Discouraged numeric key
"3.14159" = "pi" # quoted to avoid nesting
Visual
Key Forms
┌─────────────────────────────────────────────────────────┐
│ THREE KEY FORMS │
│ │
│ BARE: name = "app" │
│ ┌──────────────────────────────────────────┐ │
│ │ Allowed: A-Z a-z 0-9 _ - │ │
│ │ Excluded: spaces, dots, Unicode │ │
│ └──────────────────────────────────────────┘ │
│ │
│ QUOTED: "key with spaces" = "value" │
│ ┌──────────────────────────────────────────┐ │
│ │ Any string; basic or literal style │ │
│ │ Multi-line strings not allowed │ │
│ └──────────────────────────────────────────┘ │
│ │
│ DOTTED: fruit.apple.color = "red" │
│ ┌──────────────────────────────────────────┐ │
│ │ Sequence of bare/quoted keys + dots │ │
│ │ Creates a table for each segment │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
Dotted Key Table Creation
┌─────────────────────────────────────────────────────────┐
│ fruit.apple.color = "red" │
│ │
│ fruit ──► created (implicit table) │
│ │ │
│ └── apple ──► created (implicit table) │
│ │ │
│ └── color = "red" (key in apple table) │
│ │
│ Now INVALID: [fruit] or [fruit.apple] │
│ Now VALID: [fruit.apple.texture] (new sub-table) │
└─────────────────────────────────────────────────────────┘
Quoted Segment vs Structural Dot
┌─────────────────────────────────────────────────────────┐
│ site."google.com" = true │
│ │ │
│ └──► quoted: dot is part of the key name │
│ │
│ Parsed: { site: { "google.com": true } } │
│ │
│ site.google.com = true │
│ │ │
│ └──► unquoted: each dot is structural │
│ │
│ Parsed: { site: { google: { com: true } } } │
└─────────────────────────────────────────────────────────┘
Redefinition Rule
┌─────────────────────────────────────────────────────────┐
│ VALID │
│ │
│ [fruit] │
│ apple.color = "red" ◄── dotted key inside table │
│ │
│ [fruit.apple.texture] ◄── new sub-table, valid │
│ smooth = true │
│ │
│ INVALID │
│ │
│ [fruit] │
│ apple.color = "red" │
│ │
│ [fruit.apple] ◄── already created, error │
│ │
│ Dotted keys define tables; headers cannot redefine. │
└─────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Bare key characters | A-Za-z0-9_- |
| Quoted key | Any string, basic or literal |
| Dotted key | Sequence of bare/quoted keys + dots |
| Table creation | Each segment before last creates a table |
| Redefinition | Dotted-key tables cannot be opened with [table] |
| Sub-table exception | [parent.child] valid if child is new |
| Dot in key name | Quote the segment: "a.b" |
| Multi-line key | Not allowed |
Key takeaways:
- Bare keys are restricted by design. Only ASCII letters, digits, underscores, and hyphens are permitted. Anything else requires quotes .
- Quoted keys are the escape hatch. They follow string rules, including basic escapes and literal backslashes, and they allow any character in the key name.
- Dotted keys are structural. Each dot separates a segment, and each segment before the last becomes a table. A literal dot in a key name must be inside a quoted segment .
- Dotted keys and table headers cannot collide. A table created by a dotted key cannot later be opened with
[table]. The only exception is a new sub-table inside a dotted-key table . - All-digit bare keys are discouraged. A dotted key like
3.14159parses as nested tables, not as a numeric key .
Remember: A TOML key is not just an identifier; its form determines structure. A bare key is a single name. A quoted key is a name that bare syntax cannot express. A dotted key is a path that creates tables as it goes. The dot is always structural unless it is quoted, and a table created by a dot cannot be reopened by a header. When a key fails to parse, check whether it contains a character outside the bare set or a dot that was meant literally—the fix is usually to quote the segment, not to change the structure.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!