"category": "format-converter",
JSON to TOML Converter
"tldr": Paste JSON and get equivalent TOML - tables, arrays, and typed values - ready for Cargo.toml, pyproject.toml, and app configs.
Convert JSON into TOML, the config format of the Rust and modern Python ecosystems (Cargo.toml, pyproject.toml) and many Go/CLI tools. Objects become [tables], nested objects become dotted headers, and strings, numbers, booleans, and arrays keep their types.
TOML exists because JSON is unfriendly as a hand-edited config: no comments, strict commas, quoted keys. When a project migrates config from JSON to TOML, converting mechanically - rather than retyping - avoids the transcription typos that make the new config subtly differ from the old.
How to convert JSON to TOML
- 1Paste a JSON object - the top level must be an object, since every TOML document is a table.
- 2Nested objects become [table] and [table.subtable] sections.
- 3Types are preserved: strings stay quoted, numbers and booleans bare, arrays bracketed.
- 4Copy the TOML into your config file - and add comments, now that you can.
Convert JSON to TOML in code
import json, tomli_w # pip install tomli-w
with open("config.json") as f:
data = json.load(f)
print(tomli_w.dumps(data))import { stringify } from "smol-toml"; // npm install smol-toml
const toml = stringify(JSON.parse(jsonString));Frequently asked questions
Why does my top-level JSON array fail to convert?
A TOML document is a table (key-value collection) by definition - there is no such thing as a top-level array in TOML. Wrap the array in an object key first: {"items": [...]} converts to items = [...].
What JSON values have no TOML equivalent?
null - TOML has no null value by design. Represent absence by omitting the key, or use a sentinel your application understands. The converter reports an error rather than silently dropping nulls.
When should I prefer TOML over YAML or JSON for config?
TOML wins for flat-to-moderately-nested configs edited by humans: unambiguous (no YAML type-guessing where "no" becomes false), supports comments (unlike JSON), and has a real spec with dates and integers. Deeply nested structures read better in YAML; machine-to-machine data should stay JSON.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →