Xerobit

TOML to JSON Converter

Paste your TOML configuration into the input box to convert it to JSON immediately. This toml to json tool parses tables, arrays, strings, numbers, booleans, dates, and inline structures entirely in your browser, so nothing is uploaded to any server.

JSON output

{}

How to use the toml to json converter

  1. Paste or type your TOML text into the input area.
  2. Adjust the indent size if you prefer compact or expanded JSON.
  3. The JSON output updates automatically as you type.
  4. Copy the result or fix any parse errors highlighted below the output.

How the toml to json conversion works

The converter reads TOML line by line, building a nested JavaScript object that mirrors the table hierarchy. A line like [server] creates a new object at the server key. Key-value pairs are parsed according to their type: bare words become booleans or numbers, quoted strings are unescaped, and bracketed lists become arrays. Once the full object tree is built, it is serialized to JSON using standard stringification with the chosen indentation.

For example, given this TOML input:

[database]
host = "localhost"
port = 5432
ssl = true

The parser produces an object { database: { host: "localhost", port: 5432, ssl: true } }, which serializes directly to valid JSON.

Supported TOML features

This toml to json converter handles the core TOML v1.0 specification features commonly found in configuration files:

  • Key-value pairs with bare keys or quoted keys.
  • Standard tables defined with [table] headers, including dotted names like [a.b.c].
  • Array of tables using double brackets [[items]].
  • Inline tables written as { key = value }.
  • Arrays including multi-line arrays with trailing commas.
  • String types: basic strings with escape sequences, literal strings (no escaping), multi-line basic strings, and multi-line literal strings.
  • Data types: integers (decimal, hex, octal, binary), floats (inf and nan are kept as the strings "inf", "-inf" and "nan"), booleans, and dates or times (converted to ISO 8601 strings since JSON has no native date type).
  • Comments starting with # are ignored.

Common TOML to JSON mapping reference

Understanding how TOML constructs map to JSON helps when debugging configuration conversions. Here is a quick reference:

TOML syntaxJSON equivalent
key = "value""key": "value"
num = 42"num": 42
flag = true"flag": true
list = [1, 2]"list": [1, 2]
[section]"section": { ... }
[[array]]"array": [ { ... } ]
inline = { a = 1 }"inline": { "a": 1 }
dt = 2024-01-15T10:30:00Z"dt": "2024-01-15T10:30:00Z"

Dates and times are written as strings in ISO 8601 form (a space between date and time becomes T) because JSON does not have a native datetime type. Integers up to the 64-bit TOML limit keep every digit.

When to use TOML versus JSON

TOML is designed for human-written configuration files. Its syntax is less noisy than JSON: no curly braces around the root, no mandatory quotes on keys, and support for comments. JSON, on the other hand, is optimized for machine-to-machine data exchange. It is universally supported by APIs, databases, and programming languages.

A typical workflow involves writing configuration in TOML for readability, then converting it to JSON for consumption by tools that only accept JSON. This toml to json converter makes that step instant. If you also need to validate your TOML before converting, use the TOML validator. For reformatting TOML itself, the TOML formatter can help. And if your target format is YAML instead, try the TOML to YAML tool.

Handling edge cases and errors

Several edge cases require attention when converting between these formats. Duplicate keys within the same table are invalid in TOML and will produce a parse error. Dotted keys like a.b = 1 create nested objects, which can conflict with explicit table headers if used inconsistently.

JSON does not support comments, so all TOML comments are discarded during conversion. JSON also lacks native support for infinity and NaN values; these TOML float values are written as the strings "inf", "-inf" and "nan" so the information is not lost. If your TOML contains features outside the supported subset, the converter will display a descriptive error message indicating the line number and nature of the problem.

Worked examples

ExampleInputResult
Basic key-value pairsTOML input: title = "My App" / version = 2 / enabled = true{ / "title": "My App", / "version": 2, / "enabled": true / }
Tables and arraysTOML input: [database] / server = "192.168.1.1" / ports = [8001, 8002] / [[users]] / name = "Alice" / role = "admin"{ / "database": { / "server": "192.168.1.1", / "ports": [ / 8001, / 8002 / ] / }, / "users": [ / { / "name": "Alice", / "role": "admin" / } / ] / }
Inline tableTOML input: point = { x = 1, y = 2 }{ / "point": { / "x": 1, / "y": 2 / } / }

FAQ

Does this tool upload my TOML data to a server?

No. The entire toml to json conversion happens locally in your browser using JavaScript. Your configuration data never leaves your device.

What happens to TOML comments during conversion?

Comments are stripped out because JSON does not support them. Only the data structure and values are preserved in the output.

How are TOML dates handled in JSON?

TOML date, time, and datetime values are converted to ISO 8601 formatted strings, since JSON has no native date type.

Can I convert deeply nested TOML tables?

Yes. Dotted table headers like [a.b.c] and dotted keys are fully supported and produce the correct nested JSON object structure.

What about TOML infinity and NaN float values?

Since JSON does not support infinity or NaN, these values are written as the strings "inf", "-inf" and "nan" so the output stays valid JSON and nothing is silently dropped.

Is there a way to check my TOML syntax before converting?

You can use the TOML validator to check your syntax first, then return here to convert it.