OnlineTextLab
Esc

TOML Formatter

Even spacing for a TOML file, checked against TOML 1.0, with your comments left in place.

Formatted TOML

Formatted TOML appears here. The file is checked against TOML 1.0 as it is read.

Runs on your device. Your files and text are not uploaded.

About TOML Formatter

TOML files are edited by hand, so they drift: name="x" on one line, version = "1" on the next, sections with no gap between them. This tool evens out the spacing so Cargo.toml, pyproject.toml and similar files read cleanly, and it checks the file as it goes.

That second part is often the reason to use it. TOML has strict rules about redefining keys and tables, and they cause confusing failures at build time. Here you get the line number and a plain explanation before your build tool complains.

How it works

A TOML 1.0 reader written for this page parses the whole file, including multi-line strings, inline tables, arrays of tables, dates and integer limits. It applies the rules about redefinition: a key defined twice, a table opened twice, or a value that is later used as a table. Numbers are checked as well, so 007 and an integer too big for 64 bits are errors.

Formatting then rewrites spacing only. You get one space around =, one after commas in arrays, and a blank line above each table header. Your comments, key order and the literal text of every value are kept, so 0x10 stays hexadecimal and is not rewritten to 16. A comment directly above a header stays attached to it.

How to use TOML Formatter

  1. Paste into the TOML box, or press Upload to open a file. Try an example loads a messy config.
  2. If the file has a mistake, the error names the line. Fix it and the result appears as you type.
  3. Check the count of table headers and keys under the result, to see that nothing is missing.
  4. Press Copy, or Download to save formatted.toml.

A hand-edited config, tidied

Input
# App settings
name="billing"
version    = "2.4.1"
tags=["api","internal"]
[database]
host="localhost"   # local only
port=5432
pool = {min=2,max=10}
[[workers]]
name="email"
[[workers]]
name="reports"
Output
# App settings
name = "billing"
version = "2.4.1"
tags = ["api", "internal"]

[database]
host = "localhost" # local only
port = 5432
pool = { min = 2, max = 10 }

[[workers]]
name = "email"

[[workers]]
name = "reports"

Both comments survive, and so does the order of the keys. Only the gaps between tokens changed, plus the blank lines above each header.

When it helps

  • Cleaning up a Cargo.toml or pyproject.toml before a pull request
  • Finding the line behind a build error about a table or key that was defined twice
  • Checking a config for a tool such as Hugo or a Rust service after a merge
  • Confirming that a date or inline table you typed by hand is valid TOML

Tips for a better result

  • Merge conflicts often leave two copies of a section. The message about a table defined twice names the second one, so that is the place to start.
  • Text values always need quotes, and booleans must be lowercase. Those two mistakes account for many first errors in hand-written files.
  • If a project already formats TOML with its own tool, keep using that in CI so the two do not fight over style. This page is for checking and quick cleanups.

Good to know

  • It does not sort keys, align = signs or reorder tables. Layout beyond spacing stays yours.
  • It checks TOML syntax, not the schema of a given tool, so a misspelled [dependancies] section passes here.
  • TOML 1.0 rules apply, so a trailing comma in an inline table is an error, though newer drafts may relax that.
  • Config files larger than 5 MB will not open through Upload.

Questions people ask

Will formatting change what my file means?

No. Only whitespace outside values changes. Value text, comments and key order are carried over as they were, so a parser sees the same data.

Why is my inline table an error?

TOML 1.0 requires inline tables to stay on one line with no trailing comma. Move a long one to its own [table] section, which is also easier to read.

What is the difference between [x] and [[x]]?

[x] opens one table, which can only be defined once. [[x]] adds a new entry to an array of tables, so it can repeat, and each use starts a new item.

Why does it reject 007?

TOML does not allow leading zeros in integers, because they would be ambiguous. If it is an identifier, put it in quotes so that it becomes a string.

What to use next

Last reviewed . Read our editorial policy.