If you work with Rust, Python packaging, static site generators or many command-line tools, you have met TOML. Cargo.toml, pyproject.toml, Hugo's hugo.toml and plenty of application config files use it. TOML reads almost like an old-fashioned INI file, but under the surface it describes the same nested data that JSON does, and some of its syntax, especially double square brackets, is not obvious at first glance.
This guide explains TOML's building blocks by showing exactly what JSON each one produces, lists the errors that stop a file from parsing, and covers how to convert TOML to JSON in the browser, in Python and in Node.js.
Why TOML exists
TOML stands for "Tom's Obvious, Minimal Language", after its creator Tom Preston-Werner. It was designed as a configuration format that is easy for people to read and write and that maps unambiguously to a hash table. Compared with its neighbours:
| JSON | YAML | TOML | |
|---|---|---|---|
| Comments | No | Yes | Yes |
| Structure from indentation | No | Yes | No |
| Native date/time type | No | Partly | Yes |
| Implicit type guessing | No | Yes (NO, 1.10…) |
No: strings must be quoted |
| Deep nesting | Easy | Easy | Gets verbose |
TOML's strictness is its selling point: version = 1.10 is always a float, and version = "1.10" is always a string. There is no guessing. The trade-off is that deeply nested data is awkward to write, which is why TOML is used for configuration rather than for data exchange.
TOML building blocks and their JSON
Key/value pairs
title = "Billing service"
retries = 3
ratio = 0.75
enabled = true
Each line becomes a key in the top-level object: {"title": "Billing service", "retries": 3, "ratio": 0.75, "enabled": true}. Strings must be quoted, with double quotes (escapes allowed) or single quotes (literal, no escapes, handy for Windows paths such as 'C:\logs\app').
Tables
A [header] starts a table, which becomes a nested object. Everything below it, until the next header, belongs to it:
[server]
host = "0.0.0.0"
port = 8_080
becomes "server": {"host": "0.0.0.0", "port": 8080}. Underscores in numbers are only for readability.
Dotted keys
pool.max = 20 inside [database] is shorthand for a nested table, producing "database": {"pool": {"max": 20}}. Headers can be dotted too: [database.replica].
Inline tables
serde = { version = "1.0", features = ["derive"] } is a compact one-line table, common in Cargo.toml dependencies. It must fit on a single line.
Arrays of tables
The double-bracket header is the part people find confusing. Each [[jobs]] starts a new object in an array called jobs:
[[jobs]]
name = "invoices"
cron = "0 2 * * *"
[[jobs]]
name = "reminders"
cron = "0 9 * * 1"
becomes
"jobs": [
{ "name": "invoices", "cron": "0 2 * * *" },
{ "name": "reminders", "cron": "0 9 * * 1" }
]
In Cargo.toml, [[bin]] entries work exactly like this: one object per binary target.
Dates and times
TOML has first-class date-times such as started = 2024-06-01T08:30:00Z, local dates (2024-06-01) and local times (08:30:00). JSON has no date type, so a converter writes them as ISO 8601 strings: "started": "2024-06-01T08:30:00Z".
Convert TOML to JSON with our tool
The TOML to JSON Converter implements a TOML 1.0 parser in your browser.
- Open the TOML to JSON Converter and paste your file into TOML input, click Open file to load a
.tomlfile, or use Load sample, a Cargo-style manifest. - Choose the JSON indent.
- Read the JSON output. If the TOML is invalid, the error names the problem and its line and column.
- Copy the JSON or Download it as a
.jsonfile.
Two details are handled for you: dates and times become ISO 8601 strings, and integers larger than JavaScript can represent exactly (above 2^53) are written as strings so no digits are lost.
Converting to JSON is a good way to see what a TOML file means. If you are unsure whether a setting landed in the right table, the nested JSON shows it immediately.
Errors that stop a TOML file from parsing
Duplicate keys. Defining port twice in the same table is an error, not an override. The converter reports Duplicate key "port" with the line of the second definition.
Defining a table twice. Two [server] headers in one file are not allowed. Merge them into one section.
Unquoted strings. name = billing is invalid; TOML has no bare strings. Write name = "billing".
Mixing a table and a value. If database = "sqlite" exists, you cannot later add [database], because the key is already a string.
Inline tables across several lines. In TOML 1.0, { ... } must stay on one line. Use a normal [table] for anything longer.
Wrong quote style for paths. Backslashes in double-quoted strings start escapes, so "C:\new" contains a newline. Use single quotes for literal paths.
Other ways to convert TOML
Python 3.11 and later includes tomllib in the standard library:
import json, tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
print(json.dumps(data, indent=2, default=str))
default=str is needed because tomllib returns real datetime objects, which json cannot serialise on its own. Note that tomllib only reads TOML; writing requires a third-party package.
Node.js has no built-in TOML parser, so projects use a package from npm. Pick one that states TOML 1.0 compliance.
Command line. The Go-based yq tool can read TOML and output JSON, which suits shell scripts.
Inside the consuming tool. Build tools such as Cargo will tell you, with their own error messages, whether a manifest is valid. That is the final authority for tool-specific keys.
Tips
- Keep your TOML shallow. If you find yourself writing
[a.b.c.d]headers, JSON or YAML may be a better fit for that data. - Quote version strings such as
"1.10"even though TOML would keep a float as written in the file, because consumers compare versions as text. - Need the reverse? The JSON to TOML Converter turns objects into tables and arrays of objects into
[[arrays of tables]]. - For the same job with YAML files, use YAML to JSON, and to explore the converted data, open it in the JSON Viewer.
Frequently asked questions
What does [[double brackets]] mean in TOML?
It declares an array of tables. Each [[name]] header appends a new object to the array called name, and the keys below it belong to that object.
How are TOML dates converted to JSON?
As ISO 8601 strings, because JSON has no date type. Offset date-times keep their offset or Z, and local dates and times are written as plain date or time strings.
Can TOML have comments?
Yes. Everything after # on a line is a comment, except inside strings. Comments are dropped when converting to JSON, because JSON cannot hold them.
Is TOML better than YAML for configuration?
It depends. TOML avoids YAML's indentation and implicit-typing surprises, while YAML handles deeply nested data more compactly. Many tools choose TOML for flat, human-edited settings.
Why does my TOML say a key is duplicated?
A key was defined twice in the same table, possibly once directly and once through a dotted key or a repeated table header. TOML does not allow overriding; remove one of the definitions.