TOML Formatter & Validator — Complete Guide 2026
🚀 Format & Validate TOML Online Free
Beautify your TOML files with proper indentation and syntax highlighting. Validate against TOML 1.0 spec.
Format TOML NowWhat is a TOML Formatter?
A TOML formatter (also called TOML beautifier or pretty printer) takes poorly formatted TOML code and applies consistent indentation, spacing, and line breaks to make it more readable. A TOML validator checks if your TOML syntax is correct according to the TOML 1.0 specification.
Why Format TOML Files?
- Readability — Properly formatted TOML is easier to read and understand
- Maintenance — Clean formatting makes updates and debugging easier
- Team consistency — Standard formatting across team members
- Error detection — Formatting often reveals syntax issues
- Git diffs — Clean formatting produces cleaner version control diffs
TOML Syntax Basics
Comments
# This is a comment
# Use comments to explain complex configuration
key = "value" # Inline comments are also supported
Key-Value Pairs
# String values
title = "My Application"
description = "A sample config file"
# Numbers
port = 8080
pi = 3.14159
negative = -42
# Booleans
enabled = true
debug = false
# Dates and times
date = 2026-03-10
time = 14:30:00
datetime = 2026-03-10T14:30:00Z
Arrays
# Simple arrays
numbers = [1, 2, 3, 4, 5]
colors = ["red", "green", "blue"]
# Multi-line arrays (for readability)
long_array = [
"item1",
"item2",
"item3",
"item4"
]
Tables (Sections)
[database]
host = "localhost"
port = 5432
[server]
host = "0.0.0.0"
port = 8080
Nested Tables
[database.credentials]
username = "admin"
password = "secret"
[database.pool]
min_connections = 5
max_connections = 20
Array of Tables
[[servers]]
name = "web1"
port = 80
[[servers]]
name = "web2"
port = 81
How to Format TOML
Method 1: Online TOML Formatter (Recommended)
- Copy your unformatted TOML code
- Paste into the formatter input
- Click "Format" to see the beautified result
- Copy the formatted output
Method 2: VS Code Extension
# Install the TOML extension
# Search for "toml" in Extensions marketplace
# Recommended: "TOML" by tamasfe
# Format with: Shift+Alt+F (Windows) or Shift+Option+F (Mac)
Method 3: Command Line (taplo)
# Install taplo (TOML toolkit)
cargo install taplo-cli
# Format a file
taplo format config.toml
# Format and check
taplo lint config.toml
Method 4: Python Script
import tomlkit
# Read TOML file
with open('config.toml', 'r') as f:
toml_data = tomlkit.parse(f.read())
# Re-serialize with consistent formatting
formatted = tomlkit.dumps(toml_data)
# Write back
with open('config.toml', 'w') as f:
f.write(formatted)
How to Validate TOML
Method 1: Online Validator
Use an online TOML validator to quickly check syntax without installing anything.
Method 2: Python Validation
import tomllib # Python 3.11+
try:
with open('config.toml', 'rb') as f:
data = tomllib.load(f)
print("✓ Valid TOML!")
except tomllib.TOMLDecodeError as e:
print(f"✗ Invalid TOML: {e}")
Method 3: Node.js Validation
const fs = require('fs');
const toml = require('@iarna/toml');
try {
const content = fs.readFileSync('config.toml', 'utf8');
const parsed = toml.parse(content);
console.log('✓ Valid TOML!');
} catch (e) {
console.error('✗ Invalid TOML:', e.message);
}
Method 4: Command Line (taplo)
# Lint/validate TOML file
taplo lint config.toml
# Check multiple files
taplo lint "**/*.toml"
Common TOML Formatting Errors
# Wrong
title = My Application
# Correct
title = "My Application"
# Wrong
enabled = True
debug = False
# Correct
enabled = true
debug = false
# Wrong (avoid)
mixed = [1, "two", true]
# Correct (homogeneous)
items = [1, 2, 3]
names = ["one", "two", "three"]
# Wrong
[database.credentials
username = "admin"
# Correct
[database.credentials]
username = "admin"
# Wrong
port = 8080
port = 9090
# Correct (use tables for grouping)
[server]
port = 8080
[database]
port = 9090
TOML Formatting Best Practices
1. Consistent Indentation
# Use 2 or 4 spaces for nested content
[database]
host = "localhost"
port = 5432
2. Group Related Settings
# Good organization
[server]
host = "0.0.0.0"
port = 8080
[server.ssl]
enabled = true
cert = "/path/to/cert"
3. Use Comments Wisely
# Database configuration
[database]
host = "localhost" # Default for local development
port = 5432 # PostgreSQL default port
4. Multi-line for Long Arrays
# Better readability for 4+ items
dependencies = [
"serde",
"tokio",
"axum",
"tower",
"hyper"
]
5. Alphabetical Order (Optional)
# Easier to find settings
[database]
host = "localhost"
password = "secret"
port = 5432
username = "admin"
Tools for TOML Formatting
VS Code Extensions
- TOML by tamasfe — Most popular, syntax highlighting + formatting
- Better TOML — Alternative with additional features
Command Line
- taplo-cli — Official TOML toolkit, format + lint
- toml-cli — Simple formatting tool
Libraries
- tomlkit (Python) — Preserves comments and formatting
- @iarna/toml (Node.js) — Fast, TOML 1.0 compatible
- toml_edit (Rust) — Edit while preserving structure
TOML Version Comparison
| Feature | TOML 0.5 | TOML 1.0 |
|---|---|---|
| Native datetime | ✓ | ✓ |
| Inline tables | ✓ | ✓ |
| Multi-line basic strings | ✓ | ✓ |
| Hex/octal/binary ints | ✗ | ✓ |
| Local date-time | ✗ | ✓ |
Real-World TOML Examples
Cargo.toml (Rust)
[package]
name = "my-web-app"
version = "0.1.0"
edition = "2021"
authors = ["John Doe "]
description = "A web application built with Rust"
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
tower = "0.4"
[dev-dependencies]
reqwest = "0.11"
[profile.release]
lto = true
strip = true
pyproject.toml (Python Poetry)
[tool.poetry]
name = "my-python-project"
version = "0.1.0"
description = "A Python project"
authors = ["John Doe "]
[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.28.0"
fastapi = "^0.100.0"
[tool.poetry.group.dev.dependencies]
pytest = "^7.0"
black = "^23.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Hugo config.toml
baseURL = "https://example.com"
languageCode = "en-us"
title = "My Tech Blog"
theme = "hugo-coder"
[params]
author = "John Doe"
description = "Tech blog about Rust and Python"
keywords = ["rust", "python", "webdev"]
[menus]
[[menus.main]]
name = "Blog"
pageRef = "/posts"
weight = 10
Frequently Asked Questions
What is the TOML spec version?
TOML 1.0.0 is the current stable version, released in January 2021. Most modern tools support it.
Can I convert YAML to TOML?
Yes! Our TOML tools can help convert YAML configuration files to TOML format.
Does TOML support environment variables?
No, TOML doesn't natively support environment variable interpolation. Use a preprocessor or load them separately in your application.
Is TOML better than JSON for configs?
For human-edited configuration, yes. TOML is more readable, supports comments, and has a cleaner syntax.
🛠️ Try Our Free TOML Formatter
Format and validate your TOML files instantly. Supports TOML 1.0 spec with syntax highlighting.
Format TOML