TOML Formatter

Tidy a TOML file by normalising spacing around equals signs, adding blank lines before tables, re-indenting arrays and optionally sorting keys inside each table.

Use the tool

Why this tool exists

TOML is meant to be readable, but hand-edited files drift: some keys have no spaces around the equals sign, tables run together, and arrays are broken over lines in several styles. In files like Cargo.toml or pyproject.toml this makes diffs noisy.

This formatter works on the text, so your comments, including trailing ones, are kept. It sets key = value spacing, separates tables and arrays of tables with a blank line and indents multi-line arrays consistently. Multi-line strings are left exactly as written. The optional sort puts keys in alphabetical order within each table, which is useful for dependency lists, though it can also move keys you grouped on purpose. It does not validate TOML, so use the TOML to JSON tool to check. Nothing is uploaded.

How to use it

  1. Paste your TOML into the input box.
  2. Tick Sort keys within each table if you want alphabetical order.
  3. Check the output, especially tables and arrays.
  4. Copy the result, or convert to JSON to confirm the file still parses.

Frequently asked questions

Are comments preserved?

Yes, including comments after values on the same line. The formatter only changes whitespace and blank lines, never the content of keys, values or comments.

Should I sort keys?

Sorting suits long lists such as dependencies. Leave it off when the order carries meaning to readers, such as name and version at the top of a package table.

Does it check my TOML is valid?

No. For a validity check, paste the file into the TOML to JSON converter, which reports errors with a line number.

What happens to multi-line strings?

Multi-line strings keep their content and line breaks exactly as written, so text inside triple quotes is never re-indented or trimmed by the formatter.