TOML Formatter
Pretty-print and reformat TOML with consistent spacing and table syntax. Optionally sort keys alphabetically, and get a clear error with line/column when the TOML is invalid. Runs entirely in your browser.
Input
Output
Guides
The TOML Formatter cleans up and pretty-prints TOML documents. Paste in a Cargo.toml, pyproject.toml, or any other TOML config with inconsistent spacing, and get back a canonically formatted version with normalized key = value spacing and consistent table syntax.
What is TOML?
TOML (Tom's Obvious, Minimal Language) is a configuration file format designed to be easy for humans to read and unambiguous for machines to parse. It's the standard config format for a growing list of tools and ecosystems:
Cargo.toml— Rust package manifestspyproject.toml— Python project and build configuration.taplo.toml,netlify.toml,wrangler.toml— assorted build/deploy tooling
TOML documents map onto nested key-value structures using [table] headers, [[array-of-tables]] for repeated blocks, inline tables ({ a = 1, b = 2 }), and typed values (strings, integers, floats, booleans, dates, and arrays). Because the grammar allows a lot of stylistic freedom — extra whitespace around =, arbitrary blank lines, an inline table where a full [table] would work just as well — hand-edited TOML tends to drift into an inconsistent mix of styles over time.
How to use it
- Paste your TOML content into the input box (or click Try an example).
- The formatted result appears instantly in the output panel, ready to copy or download.
- Toggle Sort keys alphabetically if you want every table's keys (and top-level tables) reordered A–Z.
What the formatter does
This tool parses your TOML into a value tree and re-serializes it, which canonicalizes:
- Spacing: every pair becomes
key = valuewith exactly one space on each side of=. - Table syntax: nested objects are always written as
[table]/[table.subtable]headers — an inline table likeserde = { version = "1.0" }comes back out as its own[dependencies.serde]block, since the parser has no way to remember it was written inline. - Quoting: strings are re-emitted with consistent, JSON-style escaping.
- Array-of-tables blocks (
[[bin]]) are preserved as array-of-tables.
What it does NOT preserve
Because formatting works by fully parsing the document and rebuilding it from the parsed values (not by re-indenting the original text), two things are lost in the round-trip:
- Comments. TOML's grammar treats
#comments as insignificant whitespace, so they are not part of the parsed value tree and cannot be re-emitted. If your file has comments you want to keep, keep a copy of the original. - Original key order is preserved only when "Sort keys" is off — otherwise every table's keys are sorted alphabetically, including the top-level table.
Frequently asked questions
Does formatting change what my config means?
No — every value (string, number, boolean, date, array, table) round-trips to the same value, just re-serialized in a canonical style. Only comments are lost, and only "Sort keys" changes key order.
Why did my { inline = "table" } turn into a [section] block?
The TOML spec allows the same data to be written as either an inline table or a full [table] header — they're equivalent. The underlying parser has no concept of "this was inline," so every nested table comes back out in the full-header form.
Can I control the indentation width?
No — the formatter always writes tables flush-left with no per-depth indentation, which is valid, idiomatic TOML (this is also how cargo fmt-adjacent TOML tooling and most real-world Cargo.toml/pyproject.toml files look). There's no indent-size option to configure.
What happens with invalid TOML?
You'll get a specific error message with the line and column where parsing failed, instead of a blank or broken result.
Is my data private?
Yes. Formatting runs entirely in your browser. Your TOML content is never uploaded to a server.
Use it from code
From 3 credits per callREST API
curl -X POST https://api.iotools.cloud/v1/tool/toml-formatter \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tomlInput": "[package]\nname = \"my-project\"\nversion=\"0.1.…",
"sortKeys": ""
}'Swap in your own key from your account. The tool's fields are the body — no wrapper.
Ask an AI agent
Use the IOTools `toml-formatter` tool (TOML Formatter) on this input:
YOUR_INPUT_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.