How to Convert TOML to JSON (and Back)
TOML is a favorite for configuration — Cargo.toml, pyproject.toml, netlify.toml — because it's readable and typed. Converting it to JSON (or back) is handy when a tool speaks JSON but your config is TOML. Here's how the mapping works.
Tables become objects
A TOML table header opens a nested object, and dotted headers nest deeper:
[owner]
name = "Ada"
[servers.alpha]
ip = "10.0.0.1"
{
"owner": { "name": "Ada" },
"servers": { "alpha": { "ip": "10.0.0.1" } }
}
Arrays of tables become arrays of objects
The [[double bracket]] syntax is TOML's array of tables — each block is one element:
[[products]]
name = "Hammer"
[[products]]
name = "Nail"
{ "products": [ { "name": "Hammer" }, { "name": "Nail" } ] }
Typed values
TOML values carry types, and they map to their JSON equivalents: integers and floats become numbers, true/false become booleans, and arrays become JSON arrays. Datetimes, dates, and times are kept as strings, because JSON has no native date type. Inline tables ({ x = 1, y = 2 }) become objects.
Converting JSON back to TOML
Going the other way, nested objects become [table] headers, arrays of objects become [[array of tables]], and arrays of scalars stay inline. Because JSON has no dates, values that were TOML datetimes round-trip as quoted strings.
Related
Working with other config formats? See YAML to JSON and .env to JSON.
Try it
Paste TOML or JSON and convert instantly — everything runs in your browser, nothing uploaded.