What is a TOML to JSON converter for?
Configuration files in TOML are meant for humans: Cargo.toml, pyproject.toml, netlify.toml, Hugo's config.toml, Cloudflare's wrangler.toml. Programs, scripts and web tools rarely want to parse TOML themselves; they want JSON. Converting TOML to JSON gives you the exact data structure your file describes, in the format every language can load in one line.
The typical uses are practical. You read a pyproject.toml in a shell script with jq. You feed a Rust manifest to a dashboard. You want to check what a TOML file really contains after dotted keys, inline tables and [[array.of.tables]] have been applied, because TOML lets the same data be written in several equivalent ways and the JSON shows the single result. And when a TOML parser complains, the error on this page points at the line and column.
A conversion also shows where TOML is richer than JSON. TOML has native dates and times, hexadecimal, octal and binary integers, and special floats such as inf and nan; JSON has none of these. This converter, which runs in your browser and uploads nothing, reads TOML 1.0 and tells you in the examples below exactly what each of those becomes.
How to convert TOML to JSON
- Paste your TOML into the input box. The page opens with a small sample (name, version, two lists and a
[server]table); the direction, TOML to JSON, is fixed at the top. - The JSON appears next to it as you type. Every
[table]becomes an object and every[[table]]becomes an array of objects. - Choose the Indent (2 spaces, 4 spaces or a tab), tick Sort keys for alphabetical order, or tick Minify to get one line without spaces.
- Check dates and special numbers in the result: they are plain JSON values now, and the examples below show the exact forms.
- Press Copy or Download to save
converted.json. - If the TOML is invalid, a red box gives the line and column and the parser's reason, with the line of your input underneath.
TOML to JSON examples
A Cargo.toml manifest
Input:
[package]
name = "demo"
version = "0.3.1"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = "1"
[[bin]]
name = "cli"
path = "src/main.rs"
[[bin]]
name = "server"
path = "src/server.rs"Output:
{
"package": { "name": "demo", "version": "0.3.1", "edition": "2021" },
"dependencies": {
"serde": { "version": "1.0", "features": ["derive"] },
"tokio": "1"
},
"bin": [
{ "name": "cli", "path": "src/main.rs" },
{ "name": "server", "path": "src/server.rs" }
]
}The converter prints one item per line; the compact form above is only for space. The inline table serde = { ... } and the two [[bin]] blocks end up as an object and an array.
Numbers in other bases, dates and times
| TOML | JSON |
|---|---|
hex = 0xDEADBEEF | 3735928559 |
oct = 0o755 | 493 |
bin = 0b1101 | 13 |
under = 1_000_000 | 1000000 |
big = 9007199254740993 | 9007199254740993, kept exact |
day = 2024-05-01 | "2024-05-01" |
time = 07:32:00 | "07:32:00.000" |
odt = 1979-05-27T07:32:00Z | "1979-05-27T07:32:00.000Z" |
ldt = 1979-05-27T07:32:00 | "1979-05-27T07:32:00.000" |
inf and nan | null |
Dates become ISO 8601 strings with milliseconds. inf and nan come out as null, because JSON has no way to write them.
Dotted keys and quoted keys
a.b.c = 1, a.b.d = 2 and "quoted.key" = 3 give {"a": {"b": {"c": 1, "d": 2}}, "quoted.key": 3}. Unquoted dots build nesting; dots inside quotes stay part of the name.
Minify
With Minify on, a = 1 and b = [1,2] produce {"a":1,"b":[1,2]}, ready to embed in a request or a script.
Common errors and how to fix them
- Invalid TOML document: trying to redefine an already defined table or value (line 2, column 1): a key defined twice (
a = 1thena = 2) or a[table]header repeated. Merge the two. - Invalid TOML document: invalid value (line 1, column 8): a string without quotes, as in
name = demo. TOML strings need double or single quotes:name = "demo". The same message appears for an empty value such asa =. - Invalid TOML document: illegal character in key (line 1, column 5): YAML or JSON habits.
name: demomust bename = "demo". - Invalid TOML document: expected comma or end of structure (line 2, column 1): an array that never closes, as in
a = [1, 2followed byb = 3. Add the]. - Invalid TOML document: illegal character in numeric literal (line 2, column 6): a stray trailing comma after a plain value, as in
b = 1,. Trailing commas are only allowed inside arrays, never after a key's value.
Frequently asked questions
How do I convert TOML to JSON online?
Paste the TOML, read the JSON and press Copy or Download. The conversion happens in your browser, with no sign-up. To write TOML back, use JSON to TOML.
Are TOML comments kept?
No. JSON cannot hold comments, so every # comment is dropped. Keep the TOML as the source of truth and generate the JSON when you need it.
How does TOML map to JSON types?
Strings, booleans and arrays map directly. Integers and floats become numbers. Tables and inline tables become objects, and arrays of tables become arrays of objects. Dates and times become strings, and inf and nan become null.
Is the order of keys preserved?
The order of the TOML is kept, unless you tick Sort keys. In an array of tables, the items keep the order of their [[headers]].
Can I go from TOML to YAML?
Yes, directly, with TOML to YAML. If the TOML does not parse, the JSON and YAML pages show the same error because they share one reader. To check or reformat the JSON afterwards, use the JSON formatter.
How to convert TOML to JSON in code
JavaScript
import { parse } from 'smol-toml';
const data = parse('[package]\nname = "demo"\n[[bin]]\nname = "cli"\n');
console.log(JSON.stringify(data, null, 2));parse returns Date objects for dates; JSON.stringify turns them into ISO strings.
Python
tomllib is in the standard library since Python 3.11 and reads binary files.
import json
import tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
print(json.dumps(data, indent=2, default=str))default=str handles dates, which json cannot write.
Go
var data map[string]any
if _, err := toml.DecodeFile("Cargo.toml", &data); err != nil { // github.com/BurntSushi/toml
log.Fatal(err)
}
out, _ := json.MarshalIndent(data, "", " ")
fmt.Println(string(out))Bash
yq -p toml -o json '.' Cargo.toml # mikefarah/yq v4