Contents
How to Convert JSON to TOML
You're adopting Rust or Python packaging conventions and want your config in Cargo.toml/pyproject.toml style — but your data starts life as JSON from an API or an export. Here's how to convert it cleanly.
Method 1: CLI
Using transmute
$ cat config.json | transmute --to toml name = "my-app" version = "2.0" retries = 3
The format is auto-detected on input, so there are no flags to argue with. Nested objects become TOML sections ([server.tls]), scalars keep their types, and strings are escaped per the TOML spec.
Using dasel
$ dasel convert -r json -w toml < config.json
dasel handles many formats both ways. It's a solid alternative if you already have Go installed; otherwise a single static binary like Transmute is quicker to set up.
Method 2: Python
import json, tomli_w data = json.load(open("config.json")) with open("config.toml", "wb") as f: tomli_w.dump(data, f)
tomli_w writes TOML fast and correctly. One caveat: Python dicts must be converted to TOML-compatible types first — tuples work as arrays, sets don't.
Gotchas: JSON and TOML Are Not Equivalent
- Mixed-type arrays: TOML allows them (
items = [1, "two"]) but some round-trips through other tools will coerce types. - null: TOML has no null. A JSON
nullmust become an omitted key, an empty string, or a sentinel value — pick deliberately. - Top-level nesting depth: deeply nested JSON produces long chains of bracket-sections in TOML. If your structure nests more than ~3 levels, YAML may be the better target.
- Keys with dots:
{"a.b": 1}needs quoting in TOML ("a.b" = 1) or it silently becomes section[a]. Good generators quote; naive ones corrupt.
- Scripts/CI: Transmute CLI — JSON in, spec-correct TOML out.
- Python projects:
tomli_wfor direct file writing. - Quick checks: free web converter handles JSON ⇄ TOML locally in the browser.
Convert JSON → TOML in one click
Transmute runs the conversion on your machine — paste it in, or script it from the command line. JSON, YAML, CSV, TOML and XML, fully offline.
Get Transmute Desktop — $19 one-time → Or use the free web converter