How to Format TOML
TOML Formatting
When to Format TOML
Pretty-print TOML from Cargo.toml, pyproject.toml, Hugo configs, and Rust application settings. Consistent formatting makes diffs readable and helps spot table header mistakes, quoting issues, and inconsistent key ordering before commit.
TOML vs JSON and YAML
TOML supports comments, explicit table sections, and typed values. It is human-friendly for config files but stricter than YAML about types. Always validate after formatting to catch syntax errors from manual edits.
Developer Tips
- Run TOML Validate after formatting before git commit
- Keep table headers like
[dependencies]grouped for ecosystem consistency - Convert to JSON if you need programmatic diffing in CI pipelines
Frequently asked questions
Will formatting change TOML semantics?
Formatting re-parses and re-serializes the document. Comments may be lost. Review output before committing to version control.
What indentation does the formatter use?
Output uses consistent spacing aligned with common TOML conventions for tables and key-value pairs.