T

JSON ↔ TOML

Config-file interchange. TOML requires an object at the top level.

JSON
Loading editor…
0 B
TOML
Loading editor…
0 B

JSON to TOML Converter

Converts JSON into TOML and TOML back into JSON. TOML is the configuration format used by Rust's Cargo, Python's pyproject.toml and many Go tools — designed to be obvious to read and unambiguous to parse.

Types survive both directions, including the tables and arrays of tables that give TOML its structure.

How to use it

  1. Paste a JSON object on the left to produce TOML.
  2. Press Swap to parse a TOML configuration file into JSON.
  3. Errors from either parser are reported directly rather than being swallowed.

Why the top level must be an object

A TOML document is a table of key-value pairs, so it cannot represent a bare array or a lone scalar at the top level. Converting [1, 2] therefore reports an error rather than inventing a wrapper key you did not ask for.

Wrap the value in an object — {"items": [1, 2]} — and it converts cleanly into an array under a named key.

Tables, and how nesting is expressed

TOML expresses a nested object as a table written in [section] form, and a list of objects as an array of tables written in [[section]] form. That is why a TOML file reads as a flat list of labelled blocks rather than as an indented tree: the nesting lives in the section headers instead of in the whitespace.

It also means deeply nested JSON produces long dotted section names such as [server.tls.client]. TOML is designed for configuration a person edits by hand, so if your data is deeply nested or highly dynamic, JSON or YAML will usually express it more naturally.

Frequently asked questions

Why does my JSON array fail to convert?

Because the top level of a TOML document must be a table. Wrap the array in an object with a key and it converts to an array under that key.

Are comments in my TOML preserved?

No. JSON has no comment syntax, so comments are lost when converting to JSON and cannot be recreated coming back.

How are nested objects represented?

As TOML tables, written in [section] form, and arrays of objects as arrays of tables in [[section]] form.

Related tools

Everything on this page runs in your browser. TurboParse is a static site with no backend, so nothing you paste is uploaded, logged or stored.

Last updated .