Format TOML
The status line checks the file as you type and never changes your input. Formatting prints the file again from the parsed data, so comments are not kept in the formatted output. Live formatting runs for inputs under 300,000 characters; longer inputs wait for the Format button.
What the formatter changes
- Spacing. Every key gets
key = valuewith one space on each side of the equals sign. - Tables. One blank line goes in before each
[table]header, so a long config stays scannable. - Long arrays. An array that runs past 80 characters is printed one item per line, with a trailing comma.
- Dotted keys.
a.b.c = 1is expanded into a[a.b]header withc = 1. The meaning is the same, the shape is flatter. - Strings. Literal strings are re-printed as basic strings, so
'C:\path'becomes"C:\\path". Multi-line strings stay multi-line. - Comments. Dropped, because the formatter prints from the parsed data and comments are not data.
- Numbers and dates. Printed exactly as written.
0xDEADBEEFstays0xDEADBEEFand1979-05-27T07:32:00Zstays as it is.
What TOML is
TOML is a config file format. Tom Preston-Werner designed it to be easy to read and hard to get wrong. Rust uses it for Cargo.toml, Python uses it for pyproject.toml, and Hugo uses it for site config. A TOML file is key-value pairs grouped under [table] headers.
Indentation carries no meaning, which is the main difference from YAML. A line at the wrong indent still parses, but a stray tab, a missing quote, or a key written twice stops the parser. That is why the errors on this page name a line and a column.
Worked example
A short Cargo.toml, before formatting:
# Cargo.toml for a demo crate
[package]
name = "demo"
version="0.1.0"
edition="2021"
[dependencies]
serde={version="1.0",features=["derive"]}
tokio={version="1",features=["full"]}
[dev-dependencies]
criterion="0.5"
After formatting:
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
[dev-dependencies]
criterion = "0.5"
The comment on the first line is gone in the output. That is the one thing formatting cannot keep: the formatter prints from the parsed data, and a comment is not data.
Common TOML errors
| Error | What it usually means |
|---|---|
| Duplicate key | The same key appears twice in one table. The second one is the error. Delete it, or move it to another table. |
| Tabs cannot be used for indentation | A line starts with a tab. TOML forbids tabs for indentation. Replace the tab with spaces. |
| Unterminated string | A quote opened but never closed on the same line. Basic and literal strings cannot span lines. Use triple quotes for a multi-line string. |
| Unclosed array | A [ with no matching ]. Arrays may span lines, so the parser reads on until it finds the bracket. |
| Table already defined | Two [server] headers, or a [server] header after server.port = 80 already created the table with a dotted key. |
| Trailing comma in an inline table | {a = 1,} is not valid TOML. Inline tables take no trailing comma. Arrays do. |
Format TOML in code
Use a maintained tool in production. The two below are the usual choices: a dedicated formatter, and a parser that only checks.
Taplo, from the command line
taplo fmt Cargo.toml
Python, standard library only
import tomllib
with open("pyproject.toml", "rb") as f:
tomllib.load(f)
print("valid TOML")
tomllib ships with Python 3.11 and later. It raises an error on the first problem it finds, with a line and column, the same way this page reports errors.
Frequently asked questions
Does formatting keep my comments?
No. The formatter prints the file again from the parsed data, and comments are not data. If the file is full of comments you want to keep, use the status line only: it checks the file as you type and never changes your input.
Which TOML version does it check?
TOML v1.0.0, the current stable specification. Dotted keys, inline tables, arrays of tables, all four date and time forms, and hex, octal and binary integers are supported.
Does it catch duplicate keys?
Yes, with the line and column of the second one. Some lenient parsers keep the last value and stay quiet, which hides real config mistakes.
Can it check Cargo.toml and pyproject.toml?
Yes, and the sample buttons load a short example of each. It checks syntax only. It cannot tell you whether a key is valid for Cargo or for setuptools; that needs the tool itself.
Can I convert TOML to JSON?
Yes. Switch the output to JSON. Dates and times become strings, and integers too large for a JavaScript number stay as strings so no digits are lost.
Is my config private?
Yes. The parser runs in your browser. Nothing is uploaded, nothing is logged, and the page works offline once loaded.
Sources
TOML project, TOML v1.0.0: the specification this page checks against: keys, values, tables, and the rules behind the error table above.
The Cargo Book, The Manifest Format: what goes in a Cargo.toml, for the sample on this page.
Python documentation, tomllib: the standard library TOML parser used in the code snippet above.
Agents
Machine readable summary for AI assistants: