ToolDeck

TOML Formatter

Format and validate TOML configuration files

Try an example

TOML Input

Formatted TOML

Runs locally · Safe to paste secrets
Formatted TOML will appear here…
Also try:TOML to JSON

Last updated: April 2026

What is TOML Formatting?

TOML (Tom's Obvious Minimal Language) is a configuration file format created by Tom Preston-Werner in 2013. It maps directly to a hash table and uses explicit typing for all values. A TOML formatter takes raw or inconsistently styled TOML and re-serializes it with uniform spacing, proper indentation, and canonical key ordering. The result is a file that follows the same conventions across your entire project, making config changes easier to review in diffs.

The TOML v1.0.0 specification, finalized in January 2021, defines the grammar strictly enough that any compliant parser produces an identical data structure from the same input. Formatting does not change the semantic content of a TOML file. It adjusts only whitespace, key grouping, and quoting style. This means you can format TOML files freely without worrying about breaking your application's behavior.

Unlike JSON, TOML supports comments, native date-time types, and multiple string forms (basic, literal, and multi-line). A good formatter preserves comments and respects the distinction between inline tables and standard table headers. It also handles arrays of tables correctly, keeping section grouping intact so the file stays readable for both humans and the parsers consuming it.

Before · toml
After · toml
title="My App"
version="1.0.0"
debug=false
[database]
host="localhost"
port=5432
name="mydb"
[database.pool]
max_connections=25
timeout=30
[[servers]]
name="web"
host="web.example.com"
[[servers]]
name="api"
host="api.example.com"
title = "My App"
version = "1.0.0"
debug = false

[database]
host = "localhost"
port = 5432
name = "mydb"

[database.pool]
max_connections = 25
timeout = 30

[[servers]]
name = "web"
host = "web.example.com"

[[servers]]
name = "api"
host = "api.example.com"

Why Use a TOML Formatter?

Configuration files accumulate style drift as different team members edit them over time. Tabs mix with spaces, some keys get quoted unnecessarily, and table sections lose their visual grouping. A TOML formatter normalizes all of this in one pass.

Instant Formatting
Paste unformatted TOML and get clean, consistently styled output immediately. No CLI install, no project setup, no waiting for a build step.
🔒
Privacy-First Processing
All parsing and formatting runs in your browser. Your configuration data, including any credentials or internal hostnames, never leaves your machine.
Validation Included
The formatter parses your TOML before re-serializing it. If the input has syntax errors, you get a clear error message with the problematic line, so formatting doubles as validation.
📋
No Account Required
Open the page and start formatting. There is no sign-up, no rate limit, and no usage tracking. The tool works identically on every visit.

TOML Formatter Use Cases

Frontend Development
Format Wrangler.toml files for Cloudflare Workers projects or deno.toml configuration for Deno-based frontends. Clean formatting helps when reviewing deployment configs in pull requests.
Backend Engineering
Standardize Cargo.toml files across multiple Rust microservices. Consistent formatting makes it easy to scan dependency versions and feature flags across repositories.
DevOps and CI/CD
Format configuration files like .goreleaser.toml, netlify.toml, or Starship prompt configs before committing. Add a formatting check to CI pipelines to enforce style consistency.
QA and Testing
Quickly format test fixtures so they are readable and diffable. When a test fails due to config differences, formatted files make the actual vs. expected comparison obvious.
Data Engineering
Format Telegraf or InfluxDB configs that define data collection pipelines. These files often grow to hundreds of lines, and consistent formatting keeps them maintainable.
Learning TOML Syntax
Paste examples from documentation or tutorials and see how a formatter normalizes them. This is a fast way to learn which bracket styles, quoting rules, and table groupings are canonical.

TOML Syntax Reference

TOML has a small set of constructs. The table below lists every structural element defined in the TOML v1.0.0 specification. A formatter applies consistent spacing and grouping to all of these.

SyntaxNameNotes
key = "value"Basic key-value pairKeys are bare or quoted; values are typed
[table]Standard tableCreates a named section (hash table)
[a.b.c]Dotted tableShorthand for nested tables
[[array]]Array of tablesEach [[name]] block appends to an array
key = """...\n"""Multi-line basic stringAllows newlines, escapes processed
key = '''...\n'''Multi-line literal stringAllows newlines, no escape processing
# commentCommentExtends to end of line; not in JSON output
{inline = true}Inline tableSingle-line table, no newlines allowed

TOML vs JSON vs YAML

TOML, JSON, and YAML solve overlapping problems but make different trade-offs.

FeatureTOMLJSONYAML
Comments# line commentsNot supported# line comments
Typed valuesString, int, float, bool, datetimeString, number, bool, nullInferred (error-prone)
Nesting[table] headersCurly bracesIndentation-based
Spec strictnessStrict (one parse result)Strict (RFC 8259)Loose (multiple valid parses)
Date/time support4 native typesNone (use strings)Implicit (fragile)
Trailing commasNot allowedNot allowedN/A (no commas)

Code Examples

The examples below format TOML programmatically across different languages and tools. Each reads a file, parses it, and writes a formatted version.

JavaScript (Node.js)
import { parse, stringify } from '@iarna/toml'
import fs from 'fs'

const raw = fs.readFileSync('config.toml', 'utf-8')
const doc = parse(raw)
const formatted = stringify(doc)
// stringify() outputs canonical TOML with consistent spacing
fs.writeFileSync('config.toml', formatted)

// Quick one-liner with npx:
// npx taplo fmt config.toml
Python
import tomllib   # Python 3.11+ (read-only)
import tomli_w   # pip install tomli-w (write)

# Parse and re-serialize to format
with open("config.toml", "rb") as f:
    data = tomllib.load(f)

formatted = tomli_w.dumps(data)
# tomli_w produces sorted keys, consistent quoting, and
# proper whitespace around = signs
print(formatted)

# CLI alternative: taplo fmt config.toml
Go
package main

import (
    "fmt"
    "os"
    "github.com/BurntSushi/toml"
    "bytes"
)

func main() {
    var data map[string]interface{}
    _, err := toml.DecodeFile("config.toml", &data)
    if err != nil {
        fmt.Fprintln(os.Stderr, err) // parse error with line number
        os.Exit(1)
    }
    var buf bytes.Buffer
    enc := toml.NewEncoder(&buf)
    enc.Indent = "  "
    enc.Encode(data) // re-serialized with consistent formatting
    fmt.Print(buf.String())
}
CLI (taplo)
# Install taplo — the standard TOML toolkit
cargo install taplo-cli
# or: npm install -g @taplo/cli

# Format a single file in place
taplo fmt config.toml

# Format all .toml files in a project
taplo fmt

# Check formatting without modifying (CI-friendly)
taplo fmt --check

# Validate TOML syntax without formatting
taplo lint config.toml

Frequently Asked Questions

What does a TOML formatter do?
A TOML formatter parses the file into a data structure, then re-serializes it with consistent whitespace, key ordering, and quoting. The semantic content stays the same. Only the visual presentation changes: spacing around equals signs, blank lines between table sections, and indentation of nested values.
Is TOML formatting safe for production config files?
Yes. Formatting changes only whitespace and cosmetic details. The parsed data structure before and after formatting is identical. If the formatter encounters invalid input, it reports an error instead of producing broken output. You can verify this by parsing both versions and comparing the resulting objects.
How is TOML different from JSON?
TOML supports comments, native date-time types, multi-line strings, and table headers for organizing nested data. JSON has none of these. The format is designed for configuration files that humans read and edit. JSON is designed for data interchange between programs. You cannot use comments in JSON, which makes it harder to document config decisions inline.
Can I format TOML from the command line?
Yes. Taplo is the most widely used TOML formatter CLI. Install it with cargo install taplo-cli or npm install -g @taplo/cli, then run taplo fmt to format all .toml files in your project. It supports configuration via a taplo.toml or .taplo.toml file for custom rules.
Does formatting preserve comments in TOML files?
This browser-based formatter parses the input to a data structure and re-serializes it, which strips comments. If you need to preserve comments, use a CST-aware tool like Taplo (CLI) or toml-edit (Rust library), which operate on the concrete syntax tree instead of the parsed data.
What is the difference between TOML formatting and TOML validation?
Validation checks whether the file conforms to the specification and reports errors if it does not. Formatting goes a step further: it validates the input, then rewrites it with normalized style. Every formatting operation includes validation as its first step, so a file that formats successfully is guaranteed to be valid.
Which projects use TOML as their config format?
Rust's Cargo (Cargo.toml), Python's packaging ecosystem (pyproject.toml), Hugo static sites, Deno (deno.toml), Cloudflare Workers (wrangler.toml), InfluxDB, Telegraf, and Starship prompt all use TOML. The format gained popularity after Rust adopted it as the standard for package manifests in 2015.