TOML Formatter

Format or minify a TOML subset in the browser. Related pages: YAML · INI

What gets formatted

TOML is a common config format. This page reprints a useful subset into a steady layout, or strips comments and blank lines. YAML and INI have their own pages: YAML and INI.

How to use it

  1. Paste TOML. Update as you type is on.
  2. Mode is Format or Minify.
  3. Convert runs once. Show Example loads a document with title = "TOML", enabled = true, an [owner] table whose name is Ada, a [database] table with ports = [8000, 8001], and two [[products]] tables named Hammer and Nail.
  4. Minify keeps the same keys and drops comments and the blank lines between tables.
  5. Clear All empties both boxes. Copy Result copies the output. A broken document shows the line number.

The subset this page reads

Comments start with #. Keys may be bare, quoted or dotted. Tables use [name], and arrays of tables use [[name]]. Strings may be basic, literal or multiline. Numbers may be integers, floats, hex (0x), octal (0o), binary (0b) or digits with underscores. true and false, arrays and inline tables are read. An ISO date or time is kept as the original token, and so is a hex, octal or binary number.

Format writes simple keys first, then [tables], then [[arrays of tables]]. Comments are removed. A literal string is written back as a basic quoted string. An array of objects is written with [[name]]. Minify is the same text without the blank line before each table.

Where people use it

  • Cleaning a Cargo or tool config before committing it.
  • Checking which line a parser rejected.
  • Comparing two configs after comments are gone.

Questions

Where did the comment go?

Format and Minify both drop comments. They are not data in the parsed document.

Why did 0x10 stay 0x10?

Hex, octal, binary and date tokens are reprinted as written, not converted to decimal.