JSON to TOML

Turn JSON into TOML for Cargo, pyproject and similar config files.

Reverse
Input
JSON input
Output
Result

About this tool


TOML was designed to be an obvious, unambiguous config format, and it is what Rust (Cargo.toml), modern Python (pyproject.toml) and many Go tools expect. Converting JSON to TOML is mostly mechanical, with one significant exception: TOML has no null.

The structural difference worth understanding is that TOML expresses nesting through named table headers in square brackets rather than through indentation or braces, so a deeply nested JSON object becomes a flat sequence of [section.subsection] blocks.

How to use it

  1. Paste or upload JSONThe top level must be an object, since a TOML document is a table.
  2. ConvertPress Convert to TOML, or use Ctrl+Enter.
  3. Check for dropped nullsA warning appears if any null values were omitted, so you can decide what they should become.
  4. Copy or downloadSave as .toml or copy into your config file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Nested object with an array of tables

Input

{"title":"My App","owner":{"name":"Ada"},"servers":[{"host":"a"},{"host":"b"}]}

Output

title = "My App"

[owner]
name = "Ada"

[[servers]]
host = "a"

[[servers]]
host = "b"

The nested object becomes [owner]; the array of objects becomes repeated [[servers]] blocks.

A null value is dropped

Input

{"name":"app","version":null}

Output

name = "app"

TOML has no null, so version is omitted and a warning is shown.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

The top level must be an object
A TOML document is a table, so it cannot start with an array or a bare scalar. Converting [1,2] therefore fails with a clear error rather than inventing a wrapper key, wrap it yourself as {"items":[1,2]} so the resulting key name is your choice.
Nested objects become table headers
An object at {"database":{"server":"localhost"}} is written as a [database] header followed by its keys, and a deeper object produces [database.settings]. Order matters in the output: every plain key must appear before the first table header at its level, because a key after a header belongs to that table. The serialiser handles this ordering for you.
null has no representation, so those keys are dropped
TOML deliberately has no null type, the position is that an absent key is how you express "no value". Any key whose value is null is therefore omitted from the output entirely, and a warning tells you which. If null is meaningful in your data, replace it with a sentinel such as an empty string or false before converting.
Arrays of objects become array-of-tables
A JSON array whose entries are objects is written with the double-bracket [[name]] syntax, one block per entry. Arrays of scalars stay inline as [1, 2, 3]. TOML also requires that array elements be of a single type, so a mixed array such as [1, "a"] cannot be represented in older TOML versions.
Dates are strings on the way in
TOML has first-class date and time types, but JSON does not, so an ISO 8601 string in your JSON stays a quoted string rather than becoming a TOML datetime. Converting the other way does produce real dates, which is why a JSON to TOML to JSON round trip can change a value from a string into a date.

Limitations


  • null values are silently dropped, because TOML has no null type.
  • The top-level value must be an object.
  • Date strings remain strings rather than becoming TOML datetimes.
  • Mixed-type arrays cannot be represented in older TOML versions.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Why was a key missing from the output?
Its value was null. TOML has no null type, so the key is omitted. That is the idiomatic TOML way to say "no value". Substitute an empty string or false first if you need the key present.
Why can I not convert a JSON array?
A TOML document is a table, so it must start with key-value pairs. Wrap the array in an object first, choosing your own key name rather than having one invented.
Will my ISO date become a TOML datetime?
No. JSON has no date type, so a date is just a string and stays quoted. TOML to JSON does the reverse and produces real date values.