TOML ↔ JSON Converter
Convert between TOML config and JSON in both directions.
Overview
The TOML-to-JSON converter (and its reverse) translates between TOML config and JSON in both directions. Tables become nested objects, arrays stay as arrays, and TOML's typed scalars (datetimes, integers, floats) preserve their type through the conversion.
It's the bridge between TOML-loving Rust/Python tools and JSON-driven CI pipelines, web APIs, or scripting glue. Developers maintaining Cargo workspaces, pyproject.toml files, or any TOML-based config use a toml json converter to feed those settings into a JSON consumer.
How it works
TOML 1.0 is parsed against the full spec; the resulting tree maps directly to JSON because TOML's data model is a strict superset of JSON's plus datetime types. Tables and inline tables become objects; arrays-of-tables ([[items]]) become arrays of objects. Datetime values, which have no JSON peer, are serialised as RFC 3339 strings.
The reverse direction converts JSON to TOML by walking the tree and choosing between [section] blocks (for nested objects), [[array_of_tables]] (for arrays of objects), and inline tables (for short objects in arrays). Dates and times in JSON are kept as strings since JSON has no native datetime; if you want them re-typed as TOML datetimes, mark them explicitly.
Examples
TOML:
title = "My App"
[server]
host = "localhost"
port = 8080
[[users]]
name = "Alice"
JSON:
{
"title": "My App",
"server": { "host": "localhost", "port": 8080 },
"users": [{ "name": "Alice" }]
}
JSON to TOML:
{ "build": { "target": "release", "features": ["a","b"] } }
[build]
target = "release"
features = ["a", "b"]
FAQ
Are TOML datetimes preserved in JSON?
They're serialised as RFC 3339 strings, which is the closest JSON peer. Mark a JSON string with a type hint if you want it converted back to a TOML datetime on the return trip.
Why is dotted-key TOML expanded to nested JSON?
TOML dotted keys (a.b.c = 1) are syntactic sugar for nested tables, so they're expanded to nested objects ({"a":{"b":{"c":1}}}) for round-tripping fidelity. The reverse direction restores them as nested tables, not dotted keys.
Do comments survive the round trip?
JSON has no comment syntax. TOML comments are dropped when converting to JSON. If comments matter, keep the TOML source authoritative.