TOML Formatter & Validator - Format TOML Online
Format, validate, and convert TOML configuration files with syntax highlighting and tree view. Convert between TOML and JSON — 100% client-side, your data never leaves your browser.
Frequently Asked Questions
What is a TOML formatter?
A TOML formatter is a tool that takes TOML (Tom's Obvious, Minimal Language) configuration files and reformats them with consistent structure and spacing. TOML is a configuration file format designed to be easy to read, widely used in Rust (Cargo.toml), Python (pyproject.toml), Go, and many other ecosystems. A formatter ensures your TOML files follow consistent style conventions, making them easier to read, maintain, and review in version control diffs.
How do I use this TOML formatter?
Select your desired operation using the Mode options: Format (reformat TOML), TOML → JSON (convert to JSON), or JSON → TOML (convert to TOML). Paste your content into the input area or upload a file. The tool automatically validates and processes your input in real-time. Review the output in the right panel, switch to Tree view for hierarchical visualization, and use the Copy or Download buttons to save the result.
Is my data safe? Does it get sent to a server?
Your data is 100% safe and never leaves your browser. This TOML formatter uses the smol-toml library running entirely in client-side JavaScript. No data is transmitted to any server, stored in any database, or logged anywhere. All parsing, validation, formatting, and conversion happens locally on your device. You can verify this by disconnecting from the internet — the tool works fully offline after the initial page load. This makes it safe for formatting configuration files that may contain API keys, database credentials, and other sensitive secrets.
What TOML features are supported?
This tool supports the full TOML v1.0.0 specification including: basic and literal strings (single-line and multi-line), integers (decimal, hex, octal, binary), floats (including inf and nan), booleans, offset date-times, local date-times, local dates, local times, arrays, standard tables ([table]), inline tables ({ key = value }), arrays of tables ([[array]]), dotted keys (a.b.c = value), and comments (# comment). All data types are fully preserved during formatting.
Why might my TOML parsing fail?
Common reasons for TOML parsing errors include: duplicate keys in the same table, mixed types within an array (TOML arrays must contain elements of the same type in v1.0.0), invalid date/time formats (must follow RFC 3339), unclosed strings or missing closing quotes, defining a table that was already defined as an inline table, and bare keys containing invalid characters (only alphanumeric, dash, and underscore are allowed). The error message will show the exact line and column where the issue was detected.
What is the difference between TOML, YAML, and JSON?
TOML, YAML, and JSON are all data serialization formats used for configuration. JSON uses braces and brackets, requires double-quoted keys, and has no comment support. YAML uses indentation-based structure, supports comments, but is error-prone due to indentation sensitivity and implicit type coercion (e.g., 'no' becomes false). TOML uses explicit table headers ([section]) and key-value pairs, supports comments with #, has unambiguous type handling, and is specifically designed for configuration files. TOML avoids YAML's indentation pitfalls while being more human-readable than JSON.
Code Examples
// TOML parsing and formatting using smol-toml
// Install: npm install smol-toml
import { parse, stringify } from 'smol-toml';
// Parse and validate TOML
function validateToml(input) {
try {
const parsed = parse(input);
return { valid: true, data: parsed };
} catch (error) {
return { valid: false, error: error.message };
}
}
// Format TOML (parse then re-serialize)
function formatToml(input) {
const parsed = parse(input);
return stringify(parsed);
}
// Convert TOML to JSON
function tomlToJson(tomlString, indent = 2) {
const parsed = parse(tomlString);
return JSON.stringify(parsed, null, indent);
}
// Convert JSON to TOML
function jsonToToml(jsonString) {
const parsed = JSON.parse(jsonString);
return stringify(parsed);
}
// Example usage
const toml = `
[package]
name = "my-project"
version = "0.1.0"
[dependencies]
serde = "1.0"
`;
const result = validateToml(toml);
if (result.valid) {
console.log('Package:', result.data.package.name);
console.log('JSON:', tomlToJson(toml));
}
What happens to TOML comments during conversion to JSON?
TOML comments (lines starting with #) are lost when converting TOML to JSON because JSON does not support comments. This is a fundamental limitation of the JSON format, not a limitation of this tool. If you convert TOML to JSON and then back to TOML, the comments will not be preserved. For this reason, we recommend keeping a backup of your original TOML file if it contains important comments.