TOML to JSON converter — read Cargo.toml and pyproject.toml as JSON

Paste a TOML file and get the same data as JSON, with tables as nested objects, arrays of tables as arrays and dates as ISO strings, plus a pinpointed error if the TOML is invalid.

Live demo · real result from this tool
Indent

JSON

{  "package": {    "name": "toolsrift",    "version": "1.4.0",    "authors": [      "Asha Rao <asha@example.com>"    ]  },  "dependencies": {    "serde": {      "version": "1.0",      "features": [        "derive"      ]    }  },  "bin": [    {      "name": "cli",      "path": "src/main.rs"    }
  ]
}

Processed on your device — nothing is uploaded.

How to use the TOML to JSON converter

  1. Paste TOML into the Input box. The sample is a short Cargo.toml.
  2. Choose the Indent: 2 spaces, 4 spaces or Compact.
  3. Copy the JSON, or download it as config.json.

What it does and when to use it

Many tools read their settings from TOML, but scripts, dashboards and APIs usually want JSON. Converting lets you feed pyproject.toml metadata into a CI script, inspect a Cargo.toml with jq, or store a Hugo or Netlify config in a JSON database. It is also a good way to check how a TOML file nests: dotted headers such as [tool.ruff] are easy to misread, and the JSON makes each level explicit.

The reverse direction is JSON to TOML. To tidy a TOML file without converting it, use the TOML formatter, and for YAML configs try YAML to JSON.

How it works

The smol-toml library is loaded into your browser and parses the text under TOML 1.0 rules. It rejects anything invalid, such as a key defined twice, an unfinished string or a table header repeated. The parsed data then goes through JSON.stringify with your indent:

TOML JSON
[table] and [a.b] headers nested objects
[[name]] blocks an array of objects
inline arrays arrays
hex, octal and binary integers decimal numbers
dates and times ISO 8601 strings
inf, nan null

Nothing is sent to a server.

Worked examples

These are the tool’s own outputs.

The sample Cargo.toml. The single [[bin]] block becomes an array holding one object:

  "bin": [
    {
      "name": "cli",
      "path": "src/main.rs"
    }
  ]

A pyproject.toml with 4-space indent. [project] with a dependencies array and [tool.ruff] with line-length = 100 give a "project" object and a "tool" object that contains "ruff": { "line-length": 100 }.

Special values, compact. This TOML:

released = 1979-05-27T07:32:00-08:00
day = 1979-05-27
local = 07:32:00
hex = 0xff
inf = inf
ratio = 1.0

becomes {"released":"1979-05-27T07:32:00.000-08:00","day":"1979-05-27","local":"07:32:00.000","hex":255,"inf":null,"ratio":1}.

An unclosed string. title = 'unclosed returns “Invalid TOML document: unfinished string” with a caret at the opening quote.

Limits and tips

  • Integers beyond 2^53 cannot be held exactly in JavaScript; the parser stops with an error rather than rounding them.
  • Types are flattened as shown in the table, so a round trip back to TOML turns date strings into quoted strings.
  • Key order is kept within each table.

Frequently asked questions

How are TOML dates converted?
JSON has no date type, so every TOML date, time or datetime becomes a string in ISO 8601 form. Times gain milliseconds, so 07:32:00 becomes 07:32:00.000, and an offset such as -08:00 is kept.
Why did inf turn into null?
TOML allows inf and nan as float values, but JSON has no way to write them. JSON.stringify writes them as null. Check any special float values after converting.
Does 1.0 stay a float?
JSON writes 1.0 as 1, because JSON numbers do not carry a separate float type. A program reading the JSON will usually treat it as a number either way.
Are comments carried over?
No. JSON has no comments, and the parser drops them.
What does the error message show?
The parser's reason, such as "unfinished string" or "trying to redefine an already defined table or value", followed by the lines around the problem with a caret under the exact spot.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close