Open tools · 0

About

JSON to TOML

Paste JSON, or drop a .json file, and the TOML is written as you type. Objects become [tables], arrays of objects become [[arrays of tables]], and everything else is a key = value line. TOML has no null and no top-level array, so what it cannot hold is left out or moved, and each change is named.

What it does

  • A nested object becomes a table of its own: {"server": {"port": 8080}} gives [server] with port = 8080 under it.
  • An array of objects becomes [[name]] blocks, one per object, the form Cargo.toml uses for its [[bin]] targets.
  • A key holding null is left out, since TOML has no null, and the notes count how many.
  • A null inside an array is taken out, and the notes warn that the items after it moved up.
  • A whole number past 64 bits, such as a 20-digit id, is written as a string, because TOML readers refuse it as a number.
  • Keys with spaces or dots go in quotes, so "a.b" stays one key rather than a table inside a table.
  • A string with line breaks is written between triple quotes, one line per line.
  • Plain values go above an object’s sub-tables, as TOML requires, and the notes say when that moved a key.

How to use it

  1. Drop the .json file on the window, or paste its text.
  2. Tick Sort keys if the keys should come in A to Z order.
  3. Read the notes for keys left out, moved or quoted.
  4. Copy the TOML, or download it as a .toml file.

What it does not do

  • A top-level array as it is: a TOML file starts with a table, so the array goes under a key named root, and the notes say so.
  • Dates from strings: "2024-01-01" in JSON stays a quoted string, because nothing in JSON says it is a date.
  • Comments: JSON has none to carry, so any the TOML needs are added by hand.

Questions

Why did some of my keys disappear?

They held null, which TOML has no way to write. Leaving a key out is how a TOML file says “not set”, and the notes give the count. Give those keys a value in the JSON first if the program needs them.

What is the difference between [table] and [[table]]?

A [server] line starts one table, so the keys under it belong to server. A [[server]] line adds one more item to an array of tables, so writing it twice gives a list of two. JSON objects become the first, arrays of objects the second.

Will a TOML reader accept the result?

It is written to TOML 1.0, and this site’s tests read thousands of its files back with Python’s tomli. Integers past 64 bits go in quotes because the specification tells readers to refuse them.

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