Skip to the tool
DevToolBench

JSON to TOML Converter

JSON into TOML 1.0 tables, with the path of every null.

0 chars
TOML lines
0
Tables
0
Date-like strings
0
Characters
0

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

What the converter does

This JSON to TOML converter turns a JSON object into a TOML 1.0 document as you type, entirely in your browser. Nested objects become [section] tables, lists of objects become arrays of tables, everything else sits on the line of its key, and keys are quoted only when TOML requires it. It is the quickest way to convert JSON to TOML when a tool such as Cargo, Poetry, pyproject.toml, Hugo or a Netlify config wants TOML and the data you have is JSON.

The output is meant to be read and edited by a person afterwards, which is the reason to use TOML at all: short lines, one value per line, sections you can scan. TOML is also the less forgiving of the two popular config formats in one useful way: there is no indentation to get wrong, and a value's type never depends on whether it happens to look like a number or a boolean. What you see after the equals sign is exactly what the program reads.

TOML syntax in one screen

A TOML file is a table of key = value pairs. Strings are always quoted, numbers and true and false are not. A header such as [database] starts a new table, and [database.connection] a table inside it — the parent does not need its own header, so an object that only holds other objects never gets one here.

Keys made of letters, digits, - and _ are written bare. Anything else, including a dot, a space or an accented letter, is wrapped in double quotes, both in the pair and in the header, because an unquoted dot would mean nesting. Inline tables, { x = 1, y = 2 }, are used where a header is not possible: inside a list that also holds numbers or strings.

Multi-line text is written as a """ block when it is the value of a key, so a script or a certificate stays readable. Inside inline lists and tables it is escaped with \n instead, because inline tables must fit on one line.

TOML array of tables

A JSON list whose items are all objects becomes an array of tables: each item gets its own [[servers]] header followed by its keys. Nested lists of objects repeat the pattern with a longer name, [[servers.disks]], which belongs to the [[servers]] above it. A list that mixes objects with other values cannot use that form, so it is written inline instead.

What does not translate

null has no TOML equivalent at all, and the converter stops with the path of the first one instead of dropping the key without telling you. Dates stay strings: JSON cannot tell a date from text, so nothing is converted by guesswork, and the tool reports how many values look like dates. Large numbers lose precision before they reach this page, because JSON.parse stores every number as a 64-bit float; IDs longer than 15 digits belong in strings. And a JSON 1.0 arrives as 1, so it is written as an integer.

To go from JSON to the other popular config format, use the JSON to YAML converter. To tidy or validate the JSON first, there is the JSON formatter.

Frequently asked questions

Why does my JSON with null values fail to convert?

Because TOML has no null. A key either exists with a value or does not exist at all, and there is no third state to translate null into. The error names the exact path, such as servers[1].ip, so you can decide whether the key should be removed, set to an empty string, or set to false.

Why did my dates stay as quoted strings?

TOML has real date and time types, but JSON does not, so a date in JSON is only text that happens to look like one. Guessing would turn a version string or an ID that resembles a date into a different type. The converter counts the values that look like dates and tells you, so you can remove the quotes by hand where your program expects a TOML date.

Why is the key order different from my JSON?

TOML requires every plain key = value pair of a table to appear before its sub-tables, because a [section] header ends the table above it. So simple values move up and sections follow, each group keeping its original order. The data is the same; only the layout changes.

Can the top level of the JSON be an array?

No. A TOML document is always a table, so the outermost value has to be an object with keys. Wrap the array in a key, for example {"items": [...]}, and it will come out as an array of tables named items.

Is anything uploaded?

No. The JSON is parsed and the TOML is written by JavaScript in this page, without any network request. You can disconnect from the internet after the page loads and it will keep working.

Related tools

Updated