TOML to JSON Converter

Parses TOML text, top-level keys, [section] tables, and [[section]] array-of-tables, into an equivalent JSON object, so Cargo.toml, pyproject.toml, or any TOML config can be inspected or consumed as JSON. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

TOML config files, Cargo.toml, pyproject.toml, a CLI tool's settings file, are easy to read but awkward to consume programmatically from a JavaScript codebase that already speaks JSON everywhere else.

This tool parses TOML text directly into JSON, translating [section] tables and [[section]] array-of-tables into the equivalent nested objects and arrays.

What Is TOML to JSON Converter?

A TOML parser that reads key = value lines, [section] headers, and [[section]] array-of-tables blocks and builds the equivalent JSON structure, section headers becoming nested objects and repeated array-of-tables headers becoming arrays of objects.

It covers the common subset of TOML most config files use rather than the full v1.0.0 grammar, so exotic features like inline tables and datetimes aren't parsed.

How TOML to JSON Converter Works

The parser walks the document line by line, tracking the current table path. A [section] line switches the active object to that nested path, key = value lines assign into whatever object is currently active, and a [[section]] line appends a fresh object to an array at that path and makes it the active object for subsequent keys.

Scalar values (quoted strings, integers, floats, true/false) and inline arrays ([a, b, c]) are parsed directly into their JSON equivalents as each key = value line is read.

When To Use TOML to JSON Converter

Use it when you need to read a Cargo.toml, pyproject.toml, or any TOML config file from JavaScript/TypeScript code that expects JSON.

It's also useful for quickly inspecting a TOML file's structure by seeing it rendered as familiar JSON.

Features

Advantages

  • Correctly reconstructs nested tables and repeated array-of-tables blocks into properly nested JSON.
  • Reports a specific line and column for malformed TOML instead of failing silently.
  • Runs entirely client-side, so config content never leaves the browser.

Limitations

  • Doesn't parse TOML datetime literals, inline tables ({ a = 1 }), or dotted-key syntax (a.b = 1 on one line).
  • Targets the common subset of real-world TOML config files, not full v1.0.0 spec coverage.

Examples

Table with a nested key

Input

[db]
host = "localhost"
port = 5432

Output

{
  "db": {
    "host": "localhost",
    "port": 5432
  }
}

The [db] header opens a nested object, and both key = value lines below it are assigned into that object.

Invalid TOML

Input

[db
host = "localhost"

Output

Invalid TOML: unterminated section header at line 1

A [section] header missing its closing bracket is reported with the exact line where parsing failed.

Best Practices & Notes

Best Practices

  • Check the reported line/column against the source file when parsing fails, most errors come from an unterminated header or a stray key outside any table.
  • Avoid TOML datetime and inline-table syntax in files you plan to run through this converter.
  • Pair with JSON to TOML to round-trip and verify a conversion looks the way you expect.

Developer Notes

Parsing is done with decodeToml() from the site's shared TOML core module (also used by the xml category's TOML converters), which tracks a "current object" pointer that gets reassigned on every [section] or [[section]] line rather than building a full AST first, keeping the implementation a single pass over the source lines.

TOML to JSON Converter Use Cases

  • Reading a Cargo.toml or pyproject.toml file's structure from a JavaScript build script
  • Converting a TOML config into JSON for a tool that only accepts JSON input
  • Inspecting a TOML file's nested table structure by viewing it as JSON

Common Mistakes

  • Expecting TOML datetime values to convert to a JS Date-equivalent; they aren't parsed by this subset.
  • Using inline table syntax ({ a = 1 }) and expecting it to expand the same way a [section] header does.
  • Forgetting that repeated [[section]] headers become an array, not a single overwritten object.

Tips

  • If the output looks wrong, check for a stray key = value line that landed outside any [section] header.
  • Use JSON to TOML afterward to confirm the round trip preserves your data as expected.

References

Frequently Asked Questions