How to convert JSON to TOML
- Paste JSON or XML into the editor. The top level has to be an object, not an array.
- Click Format first if you want to check that the input is valid.
- Click Convert to TOML. The result appears on the right.
- Copy it into your
.tomlfile or download it.
How JSON maps to TOML
| JSON | TOML |
|---|---|
"title": "Demo" | title = "Demo" |
"ports": [80, 443] | ports = [80, 443] |
"owner": { … } | a [owner] table |
"servers": [{ … }, { … }] | one [[servers]] block per item |
null | left out, because TOML has no null |
Example
{
"title": "Demo",
"ports": [80, 443],
"owner": { "name": "Ada" },
"servers": [
{ "ip": "10.0.0.1", "role": { "primary": true } },
{ "ip": "10.0.0.2" }
]
}
becomes
title = "Demo"
ports = [80, 443]
[owner]
name = "Ada"
[[servers]]
ip = "10.0.0.1"
[servers.role]
primary = true
[[servers]]
ip = "10.0.0.2"
Plain values always come before any table, because in TOML a key belongs to the last table heading above it. Keys with spaces or other special characters are wrapped in quotes, for example "first name" = "Ada".
Where you'll meet TOML
Cargo.tomlin every Rust projectpyproject.tomlfor Python packaging and tools like Black, Ruff and pytest- Static site generators such as Hugo, and deployment config such as
netlify.toml - Many command-line tools that want a config file people can edit by hand
TOML was designed so that one file maps to one clear structure, with none of YAML's indentation surprises. That is why it is popular for configuration that people maintain by hand.
Frequently asked questions
Why is one of my fields missing after conversion?
It was most likely null. TOML has no null value, so those keys are skipped. If the target tool needs the key, give it an empty string or a default value in the source.
Why do I get an error about a top-level array?
A TOML document is always a table of keys, so the input must be a JSON object. Wrap the array in an object, for example {"items": [ … ]}, and it becomes [[items]] blocks.
Can I convert TOML back to JSON?
Not on this page at the moment. The converter works from JSON or XML to TOML.