Format TOML without losing comments
Paste TOML, validate it, then normalize spacing, sorting, arrays and blank lines while preserving comments and literal values where possible.
About this tool
Use this TOML formatter when you want a clean, validated config file without turning it into a lossy value dump. It parses the document first, reports invalid TOML with line and column context, then emits normalized spacing, table ordering, key ordering and array layout according to the options you choose.
Unlike simple value-model formatters, this formatter keeps own-line comments, end-of-line comments, scalar literal spelling such as 0xFF or 1_000_000, and literal strings wherever the requested layout can still represent them. That makes it suitable for Cargo.toml, pyproject.toml, taplo.toml and other hand-edited configuration files.
Worked example
Input:
# Package metadata
[package]
version="0.1.0"
name='demo' # literal spelling kept
features=["cli","web","docs"]
With the defaults, the output becomes:
# Package metadata
[package]
version = "0.1.0"
name = 'demo' # literal spelling kept
features = ["cli", "web", "docs"]
Choose sort_keys=asc to alphabetize entries within each table, array_style=expand for one item per line, spacing=compact for key=value, or disable keep_comments when you intentionally want a comment-free file.
Limits and edge cases
- Input must be valid TOML. Invalid input returns an error and no formatted output.
array_style=collapsecannot preserve comments inside arrays because a single-line array cannot safely contain#comments.- Output uses LF line endings and a trailing newline.
- This is a one-document formatter. For many files, run the CLI command in a shell loop.
FAQ
Does this preserve TOML comments?
Yes for normal own-line comments and end-of-line comments on entries or table headers. Comments inside arrays are preserved when the array remains expanded; forcing array_style=collapse drops those inner comments because they cannot be represented safely on one line.
Will formatting change numeric or string values?
The parser validates values, but scalar literals are emitted from the syntax tree rather than reconstructed from a generic value model. That means spellings such as 0xFF, 1_000_000, date offsets and literal strings are kept instead of being rewritten.
What does the key sorting option sort?
sort_keys=asc and sort_keys=desc sort entries within each table and keys inside inline tables. They do not reorder array values because array order is often meaningful in TOML configuration.
Why is the default indent set to zero?
Most common TOML files, including Cargo.toml and pyproject.toml, keep entries flat under each table header. The default follows that convention; set the indent slider above zero if you prefer nested table entries to be indented.
Developer & Automation Access
Run it from the terminal
Same engine as this page, headless — via the gizza CLI:
gizza tool toml-formatter "# Package metadata
[package]
name='demo'
version = \"0.1.0\"
features=[\"cli\", \"web\"]"New to the CLI? Get gizza →
Open it by URL
Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:
https://gizza.ai/tools/toml-formatter/?input=%23%20Package%20metadata%0A%5Bpackage%5D%0Aname%3D%27demo%27%0Aversion%20%3D%20%220.1.0%22%0Afeatures%3D%5B%22cli%22%2C%20%22web%22%5D&indent=0&sort_keys=preserve&spacing=standard&array_style=auto&column_width=80&align_values=true&blank_line_before_tables=true&keep_comments=trueMachine-readable descriptor: tool.json — title + parameters JSON Schema for agents.
