Developer Tools

TOML Formatter

Tidy TOML files such as Cargo.toml, pyproject.toml and application configs. The formatter normalises spacing around equals signs and commas, puts one blank line before each table, can align values and indent sub-tables, and keeps every comment. After formatting, the result is parsed again and compared with the original data, so nothing changes except the layout.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use TOML Formatter

  1. Paste TOML or open a .toml file.
  2. Choose alignment and indentation options.
  3. Click Format.
  4. Copy or download the result.

TOML Formatter features

Comments kept

Line and trailing comments stay in place.

Consistent spacing

key = value, commas followed by one space.

Table layout

One blank line before each [table] and [[array]].

Alignment

Optionally aligns = signs within a table.

Safety check

Re-parses the output and verifies the data is identical.

Normalise mode

Rewrites from the parsed data when you want a canonical form.

When to use TOML Formatter

  • Cleaning up a Cargo.toml before a release.
  • Making pyproject.toml consistent across a team.
  • Tidying configuration files edited by hand.
  • Producing a canonical form to compare two TOML files.

TOML Formatter FAQ

Is the data changed?

No. Tidy mode only changes whitespace and blank lines, and the output is parsed again to confirm the data is identical. If that check fails, the data is normalised instead and you are told.

Why are comments dropped in normalise mode?

Normalising writes the file from the parsed data, and comments are not data. Use tidy mode to keep them.

Which TOML version is supported?

TOML 1.0, the version used by Cargo, Poetry, pip and most tools.

Should I align = signs?

It is a matter of taste. Alignment looks tidy but makes diffs larger when a longer key is added.

What does indenting sub-tables do?

It indents [a.b] tables and their keys under [a], which some people find easier to read. TOML ignores the indentation.

Is my file uploaded?

No. Formatting runs in your browser.

Tidy TOML

TOML is designed to be a minimal, obvious configuration format, and it is the standard for Rust’s Cargo, Python’s pyproject.toml and many other tools. Its grammar is strict about values but relaxed about whitespace, so files edited by hand drift into inconsistent spacing and spacing between tables.

The formatter first parses the document with smol-toml, a spec-compliant TOML 1.0 parser, which reports errors such as duplicate keys or invalid values with their line and column. Only valid TOML is formatted, so the tool can be used as a quick check as well.

Tidy mode then works line by line and touches only layout. Keys and values get exactly one space around the equals sign, commas in arrays and inline tables are followed by one space, table headers get a blank line before them, and runs of blank lines are reduced to one. Comments, both on their own lines and after values, are kept.

Because a line-based formatter could in theory misread unusual syntax, the output is parsed again and compared with the original data. If anything differs, the formatter falls back to normalise mode and says so, which guarantees that formatting never changes the meaning of the file.

Normalise mode writes the file from the parsed data. The result is canonical, which makes it useful for comparing two files that were written differently, but comments are lost because they are not part of the data.

Other useful tools