JSON to TOML Converter

Top-level keys—
TOML lines—
Status—

How JSON to TOML Converter is calculated: JSON objects become TOML tables in [brackets], scalars become key = value lines, and arrays become inline [value, value] lists.

What is a JSON to TOML converter?

A JSON to TOML converter turns a JSON object into a TOML config file. TOML is the config format of Rust's Cargo, Go projects, and Python's pyproject.toml — a format designed to be obvious to humans and unambiguous to parsers. The default JSON here has 3 top-level keys, and converts to 5 lines of TOML.

The need comes up whenever a project moves between formats. A tool gives you settings as JSON, and your Rust project needs them in Cargo.toml. Or a Python package needs a pyproject.toml built from a JSON spec. Rewriting by hand means learning TOML's table syntax; a converter does it in a second.

This tool is pure JavaScript and runs entirely in your browser. Nothing is uploaded, nothing is stored, and there is no account to create. Paste the JSON, copy the TOML.

TOML was designed to be read by humans, which is why its rules are stricter than JSON in some places and looser in others. A TOML file has no braces and no commas between entries, so the structure is visible from the indentation and the section headers alone. Dates are a native type in TOML, which JSON does not have, and a date in JSON is only a string that a program must parse. The converter handles the common types — strings, numbers, booleans, arrays, and nested objects — and turns the rest into strings, because a TOML value must have a type the format understands.

How JSON to TOML conversion works

TOML has two ideas: key = value lines, and tables in square brackets. A top-level scalar such as "debug": true becomes the line "debug = true". A nested object such as "server" becomes a table: the line "[server]" followed by "host = \"localhost\"" and "port = 8080" underneath it. The default JSON has 3 top-level keys — server, debug, and tags — and the server object becomes one table.

Arrays become inline lists: "tags": ["web", "api"] becomes "tags = [\"web\", \"api\"]". Strings are double-quoted, numbers are bare, and booleans are true and false — the same as JSON, which is why the conversion is straightforward for ordinary data.

The order is preserved: top-level scalars come first, then the tables, in the order the keys appear in the JSON. That keeps the output readable, with the simple settings at the top and the grouped settings underneath in their own sections.

Tables, keys, and values, explained

A TOML table is a section, like an INI section. "[server]" groups the server settings, just as [server] does in INI. The difference is that TOML tables can nest: a table inside a table is written as "[server.tls]", with a dot, which is how a three-level JSON object converts without flattening.

Keys are bare words in TOML — no quotes needed for simple names. Values follow the same rules as JSON for the common types: strings in double quotes, numbers bare, booleans as true and false. Dates in TOML have their own format, which this converter does not produce — a JSON string that looks like a date stays a quoted string.

The one type TOML handles differently is null. TOML has no null value, so a JSON null becomes an empty string in the output. That is a deliberate choice, documented here so it does not surprise you: if a value must be absent, remove the key instead of setting it to null.

Tables are the heart of TOML, and they are what a nested JSON object becomes. An object inside an object becomes a table with a dotted name, so a config object with a server object inside it becomes a [server] table, and a deeper nesting becomes [server.tls] or similar. Arrays of objects become arrays of tables, which TOML writes with double brackets, and that is the one place where the output looks unfamiliar to a JSON reader. The converter writes those tables for you, so the structure survives the move even if the notation is new.

A worked example: a project config

Take the default JSON: a server object with host localhost and port 8080, debug true, and a tags array of web and api. That is 3 top-level keys. Convert it and you get 5 lines of TOML: "debug = true" and the tags list first, then the "[server]" table with host and port underneath.

The port stays a number — 8080, not "8080" — and the boolean stays a boolean. The tags array stays an inline list. Paste the TOML into a Cargo.toml or a pyproject.toml and it parses as the same data the JSON held, which is the test of a good converter.

Try an error to see the boundary: paste a JSON array at the top level, such as "[1, 2, 3]", and the converter reports that the top level must be a JSON object. TOML files start with key = value lines, not with a bare array, so the input needs an object to convert.

Who uses a JSON to TOML converter, and why

Rust developers are the main users. Cargo.toml is the manifest of every Rust project, and settings that arrive as JSON — from a tool, a script, or an API — need to become TOML before Cargo will read them. The converter bridges that gap in one paste.

Python developers are the second group. Since PEP 621, Python projects declare their metadata in pyproject.toml, and a JSON spec for a package needs converting into that file. Go developers are a third group, for the same reason: many Go tools read TOML configs.

Anyone writing a config by hand is a fourth group. TOML is easier to read than JSON for a config file — no braces, no trailing commas — so a developer who has settings as JSON and wants a readable config converts them once and edits the TOML from then on. A YAML to JSON converter covers the same need for YAML.

Rust developers are a third group, because Cargo.toml is the file every Rust project carries. A tool that generates project metadata as JSON — a scaffold, a form, or an API — needs that metadata in TOML before Cargo will read it, and the converter is the bridge. Python developers use the same bridge for pyproject.toml, which has replaced setup.py in most new projects. The format is the same in both cases, and the converter does not care which language will read the file.

JSON to TOML vs other converters

JSON to TOML and JSON to YAML do the same job in different formats. The JSON to YAML converter on this site turns the same JSON into YAML, which suits Docker and Kubernetes configs, while this tool turns it into TOML, which suits Rust and Python projects. The data is the same; the format is the choice.

TOML is the strictest of the three config formats, which is its strength: it has one way to write each thing, so two people writing the same config produce the same file. YAML is more flexible and more error-prone; JSON is the most verbose. Pick the format your tool reads, and convert the same JSON either way.

A JSON formatter tidies JSON that is already JSON, and an INI to JSON converter bridges the oldest config format. The tools together cover every direction a config might need to travel.

Common JSON to TOML mistakes

The first mistake is a top-level array. TOML files start with key = value lines, so a JSON array at the top level has nowhere to go. Wrap the array in an object with a key, such as {"items": [...]}, and convert that instead.

Second: null values. TOML has no null, so a JSON null becomes an empty string in the output. If a value must be absent, remove the key from the JSON before converting, rather than leaving a null that becomes an empty string.

Third: keys with dots or spaces. A JSON key such as "my key" needs quoting in TOML, and this converter writes it bare, which can fail to parse. Keep keys to letters, digits, underscores, and dashes, and the output is always valid.

Fourth: expecting dates to convert. A JSON string such as "2024-01-01" stays a quoted string in TOML, not a TOML date. If your tool needs a real TOML date, write it by hand in the TOML format, such as 2024-01-01T00:00:00Z.

A second mistake is expecting a null to survive the conversion. TOML has no null type, so the converter writes an empty string for a null value and notes it in the output, which is honest but changes the meaning — a missing value and an empty string are different things in most programs. If a null matters, replace it before converting: either drop the key or give it a real value, because the TOML file cannot carry the distinction and the program reading it will see an empty string.

How to use this JSON to TOML converter

Paste your JSON into the box — the default has 3 top-level keys — and the TOML appears instantly in the box below, with the key count and line count above it. The status reads Valid when the input parses cleanly.

To copy the result, use the Copy button next to the output box, then paste it into your Cargo.toml, pyproject.toml, or other TOML file. If the input has an error, the output names the problem — fix the JSON and paste again.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your JSON never leaves your device. It works offline once the page has loaded, so you can convert configs on a machine with no internet access.

Paste the JSON, press convert, and read the TOML before you copy it. The output starts with the top-level keys as plain assignments, then the tables, in the order the JSON held them. Check that every nested object became a table with the right dotted name, and that no key was lost — the count of keys in the output should match the count in the input. When it matches, copy the TOML into the config file, which is usually named Cargo.toml, pyproject.toml, or something similar.

Frequently Asked Questions

TOML is the config format of Rust's Cargo (Cargo.toml), Python projects (pyproject.toml), and many Go tools. It was designed to be obvious to humans and unambiguous to parsers, with tables in square brackets and key = value lines.

It becomes a table. The object {"server": {"host": "localhost"}} becomes the line [server] followed by host = "localhost" underneath. A deeper object becomes a dotted table such as [server.tls].

TOML has no null, so a JSON null becomes an empty string in the output. If a value must be absent, remove the key from the JSON before converting instead of leaving a null.

No. TOML files start with key = value lines, so a bare array has nowhere to go. Wrap the array in an object with a key, such as {"items": [...]}, and convert that instead.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.