About TOML to JSON Conversion
TOML and JSON serve overlapping but distinct purposes. TOML was designed to be obvious and minimal for humans writing configuration by hand, which is why projects like Rust's Cargo, Python's Poetry and Hatch, and many CLI tools adopted it. JSON, in contrast, is the lingua franca of machines, APIs, and tooling. Translating between them is a common need whenever a configuration value written in TOML has to be loaded by something that expects JSON, or when a JSON config is being migrated to a more readable hand-edited format.
Supported TOML 1.0 Features
- Strings — basic
"...", literal'...', multi-line basic"""...""", and multi-line literal'''...'''with all standard escape sequences. - Numbers — decimal integers, hex (
0x), octal (0o), binary (0b), underscore separators, floats, scientific notation,inf,nan. - Dates & times — offset datetimes, local datetimes, local dates, local times in ISO 8601 format.
- Booleans — lowercase
trueandfalse. - Arrays — homogeneous and mixed-type arrays, multi-line arrays with trailing commas, nested arrays.
- Tables — standard tables
[section], nested tables via dotted keys[a.b.c], inline tables{ x = 1, y = 2 }, arrays of tables[[items]]. - Keys — bare keys, quoted keys, dotted keys for hierarchy.
Quick Example
# Cargo.toml style input
[package]
name = "my-crate"
version = "0.1.0"
authors = ["Jane <[email protected]>"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = "1.30"
[[bin]]
name = "cli"
path = "src/main.rs"
Becomes:
{
"package": {
"name": "my-crate",
"version": "0.1.0",
"authors": ["Jane <[email protected]>"]
},
"dependencies": {
"serde": { "version": "1.0", "features": ["derive"] },
"tokio": "1.30"
},
"bin": [
{ "name": "cli", "path": "src/main.rs" }
]
}
How It Works
The converter parses TOML using a rigorous hand-written recursive descent parser that tokenizes line by line, tracking table context, key paths, and value types. Datetime values are preserved as RFC 3339 strings on the JSON side because JSON has no native datetime type. For the reverse direction, JSON objects become TOML tables, JSON arrays of objects become arrays of tables when possible, and primitive types map directly. All processing executes locally on your device.