How to convert TOML to JSON
Updated · 3 min read
Whether you are debugging a Cargo.toml, reading a pyproject.toml in JavaScript or feeding configuration to a tool that only understands JSON, converting TOML to JSON shows exactly how the file is interpreted. The converter implements the full TOML 1.0 specification.
- Paste TOML or drop a
.tomlfile. - Syntax errors are reported with the parser's message.
- Choose the JSON indentation in Options.
- Copy or download the JSON.
Example
TOML input
[package]
name = "dataswitch"
version = "0.4.1"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = "1"
[[bin]]
name = "dsp"
path = "src/main.rs"JSON output
{
"package": {
"name": "dataswitch",
"version": "0.4.1",
"edition": "2021"
},
"dependencies": {
"serde": {
"version": "1.0",
"features": [
"derive"
]
},
"tokio": "1"
},
"bin": [
{
"name": "dsp",
"path": "src/main.rs"
}
]
}Inline tables such as the serde entry become nested objects, and [[bin]] becomes an array — even with a single entry, because arrays of tables are always arrays.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
Supported TOML features
- Tables, dotted keys, nested and inline tables.
- Arrays and arrays of tables (
[[…]]). - Basic, literal and multi-line strings.
- Integers (including hexadecimal, octal and binary), floats, booleans.
- Offset date-times, local date-times, dates and times — written to JSON as ISO 8601 strings.
Common TOML mistakes
- Defining the same key or table twice.
- Unquoted strings:
name = my-appmust bename = "my-app". - Line breaks inside inline tables, which TOML 1.0 does not allow.
- Mixing a key and a table with the same name.
Why convert TOML to JSON?
JSON is supported everywhere: JavaScript can read it natively, jq can query it, and JSON Schema can validate it. Converting a configuration file is also a reliable way to verify its structure before committing it.
Real-world examples
Read Cargo.toml or pyproject.toml in a script
Tools written in JavaScript or shell (with jq) handle JSON more easily than TOML. Convert once to see the exact paths to the values you need.
TOML
[package]
name = "csv-tool"
version = "1.0.0"
[dependencies]
serde = { version = "1.0", features = ["derive"] }JSON
{
"package": {
"name": "csv-tool",
"version": "1.0.0"
},
"dependencies": {
"serde": {
"version": "1.0",
"features": [
"derive"
]
}
}
}Check a Netlify or Hugo config
Arrays of tables ([[redirects]]) are easy to get wrong. The JSON shows each one as an element of an array.
TOML
[build]
command = "npm run build"
publish = "dist"
[[redirects]]
from = "/old"
to = "/new"
status = 301JSON
{
"build": {
"command": "npm run build",
"publish": "dist"
},
"redirects": [
{
"from": "/old",
"to": "/new",
"status": 301
}
]
}Common errors and how to fix them
Error about a key or table defined twice
TOML forbids defining the same key or [table] header twice. Merge the two sections into one.
Strings without quotes
Unlike YAML, TOML requires quotes around every string: name = csv-tool is invalid, name = "csv-tool" is correct.
Dates came out as strings
TOML dates are converted to ISO 8601 strings, because JSON has no date type.
Windows paths break the file
Backslashes are escape characters in basic strings. Use single quotes — path = 'C:\data\in.csv' — or double the backslashes.
Related guides
Convert TOML to JSON in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Python 3.11+ (tomllib)
import json
import tomllib # built into Python 3.11+
with open("Cargo.toml", "rb") as f:
data = tomllib.load(f)
print(json.dumps(data, indent=2, default=str))
Node.js (smol-toml)
import { parse } from "smol-toml"; // npm install smol-toml
const json = JSON.stringify(parse(text), null, 2);
Frequently asked questions
How are TOML dates converted?
As ISO 8601 strings, because JSON has no date type. Date-only values stay in the form 2026-10-31.
Which TOML version is supported?
TOML 1.0, the current stable specification.
Are comments kept?
No. JSON has no comments, so they are dropped.
Can I convert TOML to YAML?
Yes. Choose YAML as the target format.
Is my file uploaded?
No. Parsing happens in your browser.