A tour of TOML v1.0.0 syntax
TOML (Tom’s Obvious, Minimal Language) is a configuration format designed to be
easy to read and to map cleanly onto a hash table. It powers Cargo.toml,
pyproject.toml and many other tool configs. This reference covers keys and
tables, every string variant, number formats, arrays and the four date-time
types.
How it works
A TOML file is a set of key/value pairs grouped into tables. A header in square brackets opens a table; dotted names create nesting; double brackets build an array of tables:
title = "Example"
[server]
host = "127.0.0.1"
ports = [80, 443]
tls = { enabled = true, min = "1.2" }
[[products]]
name = "A"
[[products]]
name = "B"
created = 1979-05-27T07:32:00Z
Every value has a clear type: integers (with _ separators and 0x/0o/0b
prefixes), floats, booleans (true/false only), strings in four flavours,
arrays, and the RFC 3339 temporal types. Files must be valid UTF-8.
The four string types
TOML’s string system is the part developers most often get wrong. Choosing correctly avoids tedious escaping:
| Type | Syntax | Escaping | When to use |
|---|---|---|---|
| Basic | "hello\nworld" | Backslash sequences | Default; supports \n, \t, \\, \", and Unicode escapes |
| Multiline basic | """....""" | Same as basic | Long strings that need line breaks in the source file |
| Literal | 'C:\Users\name' | None | Windows paths, regex, anything where backslashes should be literal |
| Multiline literal | '''...''' | None | Long literal blocks; first newline after ''' is stripped |
The most common mistake: putting a Windows path in a basic string and forgetting to escape the backslashes. Use a literal string (single quotes) and the path is copied verbatim.
Tables versus arrays of tables
Single brackets [section] open a named table. You cannot redefine it later — attempting to creates a parse error. Double brackets [[section]] append a new element to an array of tables every time they appear. This is TOML’s equivalent of a list of objects:
[[dependencies]]
name = "tokio"
version = "1"
[[dependencies]]
name = "serde"
version = "1"
This produces an array of two table objects, exactly how Cargo.toml represents your package’s dependency list.
Date-time types
TOML has four temporal types that map to common calendar objects without requiring string parsing:
1979-05-27T07:32:00Z— offset date-time (with timezone)1979-05-27T07:32:00— local date-time (no timezone)1979-05-27— local date07:32:00— local time
These are written without quotes. Parsers expose them as native date/time objects, which avoids the fragile custom string parsing that plagues formats like JSON.
Common pitfalls
- Redefining a key is a hard error, not a silent override. This is intentional and prevents the class of bugs where a config file has two contradictory values for the same key and you have to guess which wins.
- Booleans are lowercase only.
trueandfalsework;True,False,YES, andyesare parse errors. - Inline tables must be complete on one line and cannot be extended later with dotted keys.
Tips and notes
- Use literal strings (single quotes) for Windows paths and regex to avoid escaping.
[[name]]appends to an array of tables; plain[name]defines a single table.- Booleans are lowercase only; there is no
Trueoryes. - Defining the same key twice is an error — that strictness prevents silent overrides.
- In
pyproject.toml, the[tool.X]pattern uses dotted table headers to namespace each tool’s configuration within the same file.