TOML ↔ JSON Converter

Convert TOML configuration files to JSON and JSON back to TOML.

Indent:
TOML INPUT
JSON OUTPUT

When a TOML ↔ JSON converter is the right tool

Use this page to turn a TOML configuration file into indented JSON, or a JSON object back into TOML. That is useful when you want to inspect a Cargo.toml, move a config into a JSON-based tool, or check a translation in the other direction. Choose a direction, paste the source, and click Convert.

It is a data converter, not a formatter that preserves comments or original layout. For a YAML mapping instead of JSON, use YAML ↔ TOML. To compare two TOML files, use TOML Diff.

Use cases

Inspecting a Cargo-style manifest as JSON

Leave the direction on TOML → JSON and Load Sample for a short package, dependencies, bin, and release-profile document. Inline tables such as serde = { version = "1.0", features = ["derive"] } become nested JSON objects, and [[bin]] becomes an array.

Writing TOML from a JSON object

Switch to JSON → TOML and paste a single JSON object. Arrays and nested objects are valid values, but the root itself must be an object, not an array. After a successful TOML → JSON run, Swap puts the JSON into the input so you can Convert back — remember that the JSON Load Sample is a simpler object than the TOML sample.

Choosing 2-space or 4-space JSON

The indent control applies only when you are producing JSON. Pick 2 or 4, then Convert. The control is hidden in the JSON → TOML direction.

How conversion works

Both directions run only when you click Convert. @iarna/toml parses TOML into a JavaScript object, which is then pretty-printed as JSON, or JSON is parsed and stringified as TOML. Direction buttons clear the editors. Swap reuses the output as the next input but still needs a Convert. Empty or whitespace-only TOML parses as an empty object, which becomes {}.

Example — an inline table and an array of tables become JSON
[dependencies]
serde = { version = "1.0", features = ["derive"] }

[[bin]]
name = "server"

{
  "dependencies": {
    "serde": {
      "version": "1.0",
      "features": [
        "derive"
      ]
    }
  },
  "bin": [
    {
      "name": "server"
    }
  ]
}

Stringify of that same object writes [dependencies.serde] rather than an inline table. The data is the same; the layout is not a character-for-character round trip.

What this tool does not do

It does not keep comments, preserve inline-table layout, treat JSON date strings as TOML datetimes, or emit keys whose values are null. It does not update live, and it does not upload anything. Pretty-print the JSON afterwards with JSON Formatter if you want a second look at spacing or a minified copy.

How to use TOML ↔ JSON Converter

  1. Choose TOML → JSON or JSON → TOML. Switching tabs clears the input.
  2. Optionally set indent to 2 or 4 when you are producing JSON.
  3. Paste the source, or use Load Sample for a short example in the current direction.
  4. Click Convert. Use Swap if you want to feed the output back the other way, then Convert again.

Frequently asked questions

How does the conversion work?

TOML → JSON parses the input with @iarna/toml and pretty-prints the result with JSON.stringify. JSON → TOML parses with JSON.parse and writes TOML with @iarna/toml’s stringify. You have to click Convert; the output is not computed as you type. Changing the indent after a run does not rewrite the JSON until you convert again.

When does the indent control apply?

Only for TOML → JSON, and only the values 2 or 4. It is hidden in the JSON → TOML direction. TOML output has no indent control.

What do the direction buttons and Swap do?

The TOML → JSON and JSON → TOML buttons switch direction and clear both editors. Swap flips the direction, puts the current output into the input, and clears the output, so you still need to click Convert to go back. Load Sample pastes a short example for the current direction and clears the output. The two samples are not equivalent: the JSON sample flattens serde and tokio to version strings, while the TOML sample uses inline tables with features arrays.

What happens to comments, dates, and nulls?

Comments are dropped, because they are not part of the parsed data. A TOML datetime becomes a JavaScript Date and is written to JSON as an ISO-8601 string such as 2020-01-01T00:00:00.000Z. Converting that JSON back to TOML keeps it as a quoted string, not a datetime. JSON null values are omitted from the TOML. A JSON array at the root cannot be stringified — @iarna/toml reports that it can only stringify objects, not arrays.

Can I convert a Cargo.toml or pyproject.toml file?

If the file is valid TOML, yes — there is no special Cargo or Python mode. Inline tables, arrays of tables, and dotted keys parse into ordinary JSON objects and arrays. Stringify may rewrite an inline table as a dotted table header, which is still valid TOML but may not match the original layout.

Is my data sent to a server?

No. Conversion runs in your browser with @iarna/toml. Closing the tab discards what you pasted. Do not paste configuration that contains secrets if you would not be comfortable with it sitting in memory on this device.

Related tools and guides

References

  • TOML v1.0.0 is the language this page parses and writes through @iarna/toml.
  • JSON output uses standard JSON.stringify. Date objects from TOML datetimes become ISO-8601 strings in that step, which is why a datetime does not round-trip as a datetime.