TOML formatter — check and tidy Cargo.toml, pyproject.toml and config files

Paste a TOML file to check that it parses and get it re-written in one consistent layout by the smol-toml parser, with a warning when comments will be lost.

Live demo · real result from this tool

Formatted TOML

[package]name = "toolsrift"version = "1.4.0"authors = [ "Asha Rao <asha@example.com>" ] [dependencies.serde]version = "1.0"features = [ "derive" ] [[bin]]name = "cli"path = "src/main.rs"  

Processed on your device — nothing is uploaded.

How to use the TOML formatter

  1. Paste your file into the Input box. A Cargo-style sample is ready to try.
  2. The Formatted TOML appears straight away; there are no options to set.
  3. If a yellow note says comments were removed, keep your original file for the comments.
  4. Copy the result or download it as formatted.toml.

What it does and when to use it

Use it as a quick validity check before you commit a Cargo.toml, pyproject.toml, Hugo or Netlify config, and to give a hand-edited file one even layout: key = value with single spaces, arrays written as [ "a", "b" ], and one blank line before each table header.

The output also shows how a program reads your file: if a value lands in an unexpected table, your headers are wrong.

To use the data elsewhere, convert it with TOML to JSON, or go the other way with JSON to TOML. For older key=value files with [sections] and ; comments, the INI formatter keeps your comments.

How it works

The tool loads the smol-toml library in your browser and calls parse on your text. That step fails on any TOML error, such as a repeated key, a missing quote or an invalid date. If it succeeds, stringify writes the data back out:

  • simple keys first, then each sub-table under its own [a.b] header,
  • arrays of tables as [[name]] blocks,
  • strings in double quotes, dates in full ISO form.

Your text is not uploaded; parsing and printing happen on your device.

Worked examples

These are the tool’s own outputs.

The sample manifest. Its serde={version="1.0",features=["derive"]} line under [dependencies] comes out as:

[dependencies.serde]
version = "1.0"
features = [ "derive" ]

A file with comments. # build settings above title="Site" and port=8080 # dev port give title = "Site" and port = 8080 under [server], plus the note “Comments were removed by the TOML parser; keep your original if they matter.”

A duplicate key. a = 1 followed by a = 2 fails with “Invalid TOML document: trying to redefine an already defined table or value”, and a caret marks line 2.

A date. when=1979-05-27T07:32:00Z is printed as when = 1979-05-27T07:32:00.000Z.

Limits and tips

  • Comments are always lost. This is the main trade-off of a parse-and-print formatter.
  • Layout choices are fixed. You cannot choose inline tables, a different indent or a key order.
  • Floats stay floats. x = 1.0 comes back as x = 1.0 and integers stay integers, but exponent forms are written out in full, so 1e3 becomes 1000.0.
  • Large integers are kept exactly. big = 9007199254740993 is printed unchanged.

Frequently asked questions

Why did my comments disappear?
The tool reads your TOML into data and writes that data out again. TOML parsers do not keep comments, so they are lost, and a warning tells you so. Use the output to find errors or to tidy files without comments, and copy the layout back by hand if the comments matter.
Why did my inline table become a [section]?
The writer prints nested tables as their own [parent.child] headers. serde = { version = "1.0" } under [dependencies] becomes [dependencies.serde] with version on the next line. Both forms mean the same data to any TOML reader, including Cargo.
Can it find errors in my TOML?
Yes. If the file does not parse, you see the parser's message with the line and a caret under the problem, for example when a key is defined twice.
Does it keep the order of my keys?
Keys keep their order within a table, but plain values are printed before sub-tables, so a key written after a nested table may move up.
Which TOML version does it follow?
It uses smol-toml, a parser for TOML 1.0. Dates and times are read as real values and printed in a full form, so a time gains .000 milliseconds.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close