Open tools · 0

About

TOML to JSON

Paste a TOML file, such as a pyproject.toml, a Cargo.toml or an app’s config, and the JSON is written as you type. Tables become nested objects, [[arrays of tables]] become arrays, and dotted keys are opened out. What JSON has no syntax for, such as a date, a hex number or a comment, is rewritten or dropped, and named.

What it does

  • Dotted keys open into objects: a.b.c = 1 gives {"a": {"b": {"c": 1}}}, and "site.com" in quotes stays one key.
  • Dates and times become strings with their offset as written: 1979-05-27T07:32:00-08:00 keeps its -08:00.
  • Hex, octal, binary and 1_000_000 become plain decimal numbers, each named in a note.
  • TOML’s inf and nan become the strings "inf" and "nan", which JSON numbers cannot hold.
  • Multi-line strings keep their line breaks, and literal strings in single quotes keep every backslash, as Windows paths need.
  • A key written twice is refused with its line, as TOML requires, rather than one of the two being kept.
  • A whole number past 64 bits is kept digit for digit, with a warning that most TOML readers would refuse it.

How to use it

  1. Paste the TOML, or drop the .toml file.
  2. Choose the indent, and tick Sort keys for A to Z order.
  3. Read the notes on dates, numbers and comments.
  4. Copy the JSON, or download it as a .json file.

What it does not do

  • Dates as a type: JSON has none, so a program reading the result gets strings and must parse them itself.
  • Comments carried into JSON as keys: that would add data the program never had, so they are dropped and counted.

Questions

How do I read pyproject.toml as JSON?

Drop the file on the window: [project] becomes a "project" object with name, version and dependencies inside, and [tool.ruff] becomes "tool": {"ruff": {...}}. The JSON can then go to jq, a script or anything else that reads JSON but not TOML.

What happens to a local date and time?

It stays as written, with no time zone invented: 1979-05-27T07:32:00 has no offset in the TOML and none in the JSON. One written with a space instead of the T, which TOML allows, comes out with the T.

Does it work for Cargo.toml?

Yes. [dependencies] becomes an object, and an inline table such as serde = { version = "1", features = ["derive"] } becomes an object inside it, its array kept as an array.

Can I convert the JSON back to TOML?

Yes, press Swap. Tables and arrays of tables come back, but the comments do not, and keys may move, since TOML writes a table’s plain values above its sub-tables.

Everything here runs in your browser. Nothing you type, paste or open is uploaded, and there is no account and no queue. How that works.

Often used with

More in Converters

  • Unit Converter: Convert length, weight, temperature, volume, area, speed, data size and nine more quantities, both ways, with the formula.
  • Base64 Encode & Decode: Encode text or files to Base64 and decode it back: URL-safe, MIME line breaks, data URIs, and images you can preview.
  • CSV Viewer & Editor: Open a CSV, Excel or JSON file as a table, tidy it (spaces, duplicates, garbled letters, dates and numbers) and save it as CSV, .xlsx or JSON.

All toolsAbout utilbrewPrivacy