Blog

How to Convert JSON to TOML (and TOML to JSON)

Convert JSON to TOML and back the right way. Learn how nested objects become TOML tables, how arrays of objects map, and the gotchas to avoid.

TOML and JSON both have explicit types and no significant whitespace, which makes conversion predictable. The main difference is how TOML expresses nesting with tables.

How nesting maps

A nested JSON object becomes a TOML table written with brackets:

json
{
  "title": "App",
  "database": { "host": "localhost", "port": 5432 }
}

becomes

toml
title = "App"

[database]
host = "localhost"
port = 5432

Top-level scalar keys come first, then each nested object becomes its own table section.

Arrays of objects

A JSON array of objects maps to a TOML array of tables using double brackets:

json
{ "workers": [ { "name": "w1" }, { "name": "w2" } ] }

becomes

toml
[[workers]]
name = "w1"

[[workers]]
name = "w2"

TOML to JSON

Going back, every table becomes a nested object and every array-of-tables becomes an array of objects. TOML's explicit types carry over cleanly — no surprise coercion like YAML.

Gotchas

  • Deeply nested data gets verbose in TOML; JSON or YAML may read better.
  • Mixed-type arrays are restricted in older TOML versions — keep elements the same type.
  • Comments are dropped when converting to JSON.

Do it instantly

Paste your file into the formatter, choose TOML or JSON as the target, and copy. It auto-detects the source and handles tables and arrays-of-tables for you.

Got a file to check?
Paste it in. Errors come back in plain English.
Open Config Formatter & Converter →