JSON to TOML

Free online JSON to TOML converter. Paste a JSON object and instantly get a TOML v1.0 config with nested tables ([section]), subtables ([a.b]), and arrays of tables ([[items]]). Generate Cargo.toml, pyproject.toml, Hugo, and Prettier configs locally in your browser.

Related

What is TOML and why convert JSON to TOML?

TOML stands for Tom's Obvious, Minimal Language, a configuration file format created by GitHub co-founder Tom Preston-Werner in 2013. Its design goals are: obvious syntax, minimal complexity, easy human readability, and unambiguous semantics. TOML 1.0 became the stable version in 2021 (toml-lang/toml), and is now the default configuration format for the Rust Cargo ecosystem, Python PEP 621 (pyproject.toml), Hugo, Prettier, Deno, Taplo, and many other tools.

TOML has several clear advantages over JSON and YAML in configuration scenarios: ① no indentation traps like YAML — YAML relies on indentation to express hierarchy, so an indentation error can completely change the meaning of a config (a list becomes a string), whereas TOML uses explicit [table] declarations with no ambiguity; ② better than JSON for configs — JSON's quotes and curly braces are verbose for complex configs, TOML's key = value syntax is cleaner and natively supports comments; ③ explicit type system — TOML distinguishes seven types (integer/float/string/boolean/datetime/array/table), with no JSON-style ambiguity about whether a number is an integer or float, and no YAML 1.1 Norway problem (NO parsed as boolean false).

TOML's core structure consists of four elements: ① key-value pairs (key = value) for basic config items; ② Tables declared with [name] for named groups, with dot-nested support ([a.b.c]); ③ Arrays of Tables declared with [[name]] for lists of homogeneous objects, often used for multi-environment configs, plugin lists, and dependency lists; ④ Arrays supporting inline syntax ([1, 2, 3]) or multi-line form for primitive collections. The tool intelligently recognises JSON structures during conversion and picks the most appropriate TOML syntax.

Common motivations for converting JSON to TOML include: ① moving projects from the Node.js ecosystem to the Rust/Python ecosystem and unifying config formats to TOML; ② teams deciding to consolidate scattered JSON configs under TOML, leveraging TOML's [section] hierarchy to avoid the readability burden of deeply nested JSON; ③ replacing YAML with TOML to eliminate indentation-induced bugs; ④ converting upstream JSON metadata into TOML within CI/CD for downstream tooling. This tool covers all of these conversion scenarios.

The conversion process is essentially an abstract syntax tree mapping: JSON.parse() parses the text into a JavaScript object (AST), then recursively walks every node — strings, numbers, booleans and null map to the corresponding TOML scalars; arrays split into inline arrays or arrays of tables based on element type; nested objects map to tables or subtables. The final output is serialised text per the TOML specification. This structured mapping guarantees that the converted result is 100% syntactically valid, with no formatting errors.

Use Cases

  • Prepare Cargo.toml for a Rust project: convert package.json / tsconfig.json style JSON configs into TOML to match the Cargo toolchain
  • Generate pyproject.toml for Python projects: turn setup.py / setup.cfg style JSON metadata into PEP 621 standard pyproject.toml
  • Migrate Hugo / Deno / Prettier configuration: move JSON tool configs to the TOML format for cleaner section structure
  • DevOps toolchain migration: unify CI/CD pipeline configs from JSON to TOML for a consistent format across the team
  • Configuration format review: quickly turn existing JSON configs into TOML to compare and pick the best format for your project
  • Learning TOML syntax: when you already have a JSON structure and want to see how TOML expresses nested tables and arrays of tables

How to Use

  1. Paste your JSON content into the left editor, or click the upload button to select a .json / .txt file. You can also click Sample to load a complete nested example
  2. The tool parses JSON in real time and generates TOML code on the right following the v1.0 spec. Key-value pairs, nested tables and array-of-tables are written using the appropriate syntax automatically
  3. If the JSON has a syntax error, a red error message is displayed. Click the link to jump to the JSON Repair tool to auto-fix trailing commas and other common errors
  4. When you are happy with the result, click Copy to copy the TOML content, or click Download to save it as a config.toml file for your project

Features

  • Standards-compliant TOML v1.0 output: works out of the box with Cargo, Poetry, Hugo, Prettier, Deno, Taplo, and any TOML-compatible tool
  • Automatic nested-object mapping: multi-level JSON nested objects are turned into TOML tables ([a]) and subtables ([a.b.c]) with clear hierarchy
  • Smart array-of-tables detection: arrays of objects (e.g. database connection lists) are automatically rendered as TOML [[items]] tables
  • Safe string escaping: double quotes, backslashes, newlines, tabs and other special characters are escaped per TOML rules so the output is always parseable
  • Automatic type mapping: JSON strings, numbers, booleans and null map to TOML string/integer/float/boolean (null becomes empty string)
  • Real-time two-pane editor: paste JSON on the left and instantly see the TOML output on the right with no button clicks required
  • Quick-start sample data: load a complete example with nested objects, arrays and array-of-tables to see the conversion result in one click
  • File upload and download: load .json/.txt files directly, and download the converted output as config.toml in a single click
  • Resizable panels and history: drag the panel divider on desktop, automatically save the latest 200 conversions for easy rollback
  • Jump to JSON formatter: after converting, jump straight to the JSON formatter tool to beautify, validate or minify your source JSON
  • Pure local processing: all parsing and conversion runs in your browser JavaScript engine, sensitive config data never leaves your device

FAQ

How do I convert JSON to a TOML configuration file?

Paste your JSON into the left input area. The tool automatically parses the JSON object and converts it to a TOML v1.0 configuration file. Key-value pairs become key = value, nested objects become TOML tables ([section]) or subtables ([a.b]), and arrays are split into inline arrays or arrays of tables ([[items]]) based on their element types. Click the Sample button to load a nested example, and download the result as config.toml for direct use in your project.

What are the differences between TOML, YAML, and JSON?

JSON is the de facto standard for REST APIs and front-end/back-end data exchange. YAML shines for complex data structures and CI/CD configs (GitHub Actions, Ansible, Kubernetes) with great readability and support for comments and multi-document files. TOML is built for explicit configuration scenarios (Rust/Cargo, Python pyproject, Hugo, Prettier) with concise syntax, no ambiguity, and no indentation traps. There is no single best choice — TOML is recommended for configs, YAML for CI/CD, JSON for API data.

How are nested JSON objects represented in TOML?

TOML uses Tables to express nested structures. One level of nesting, such as {"database": {"host": "localhost"}}, becomes [database]\nhost = "localhost". Deeper nesting, such as {"server": {"ssl": {"enabled": true}}}, becomes [server.ssl]\nenabled = true. The tool automatically detects the nesting depth and generates the corresponding dotted table headers — no manual adjustment required.

How are JSON arrays converted to TOML?

TOML supports two array syntaxes: ① arrays of primitive types (such as ["a", "b", 1, 2]) become inline arrays key = ["a", "b", 1, 2], with comma-separated values wrapped in square brackets; ② arrays of objects (such as [{"name": "primary"}, {"name": "replica"}]) become arrays of tables [[items]], where each object is preceded by an [[items]] header with its fields flattened underneath. The tool automatically detects the array type and selects the appropriate TOML syntax.

Can the generated TOML be used directly in Cargo.toml?

Yes. The tool strictly follows the official TOML v1.0 specification (github.com/toml-lang/toml), so the output can be used directly in Cargo (Rust package manager), Poetry/pyproject (Python package manager), Hugo (static sites), Prettier, Deno, Taplo, and any other TOML-compatible toolchain. Note: if you need Cargo-specific [package] / [dependencies] sections, please add the required fields (name, version, edition, crate dependency tables, etc.) manually to match the Cargo manifest format.

What happens to JSON null values in the TOML output?

TOML has no null type, so JSON null values are converted to an empty string "" — the most common equivalent representation. If your TOML consumer has special requirements for null fields (such as the optional flag in [dependencies]), please adjust the corresponding line manually after conversion.

How are double quotes and newlines in strings handled?

TOML strings must be wrapped in double quotes. Internal double quotes, backslashes, newlines (\n), carriage returns (\r) and tabs (\t) must all be escaped per the TOML specification. The tool handles these automatically: for example, He said "Hello" in JSON becomes He said \"Hello\" in TOML, and newlines inside multi-line strings become \n. No manual escaping is needed, and the output can be parsed correctly by any TOML parser.

Does the generated TOML support date and time types?

This tool only accepts JSON as input, and JSON has no native date/time type (the common convention is to use ISO 8601 strings such as "2026-01-01T00:00:00Z"). After conversion, TOML preserves these values as strings (key = "2026-01-01T00:00:00Z"). If you need TOML's native local datetime or offset datetime types, please change the string to a bare TOML date literal (such as 2026-01-01T00:00:00) manually.

Does the local browser conversion upload my config data?

No. All JSON parsing, TOML generation and string escaping runs entirely in your browser's local JavaScript engine, with no network calls to any server. The tool keeps working even when you are offline. You can safely convert JSON containing database passwords, API keys, internal hostnames and other sensitive configuration.

Troubleshooting

JSON shows "Unexpected token" error — how to fix?

This is a JSON syntax error. Common causes: ① trailing commas, such as {"a":1,}; ② single quotes instead of double quotes, such as {'a':1} (JSON requires double quotes); ③ unquoted keys, such as {a:1}; ④ comments using // or /* */ (not supported by the JSON standard). Use the JSON Repair tool on this site to auto-fix these common errors, then paste the repaired JSON into this tool for conversion.

Cargo reports "invalid TOML" after conversion — what to do?

Usually it's a field naming conflict or a missing required field. The TOML parser is strict about table header paths, duplicate keys, and character escaping. Please check: ① whether there are duplicate keys within the same scope; ② whether special characters inside strings are correctly escaped (double quotes, backslashes, newlines); ③ whether the nesting depth is too deep (TOML 1.0 recommends no more than 5 levels); ④ whether required Cargo sections like [package] are missing. The tool's output is 100% syntactically valid, so the issue is usually on the consumer side (e.g. whether field names match Cargo's manifest rules).

Object array was converted to an inline array instead of array of tables?

A JSON array only becomes an inline array like ["a","b"] when every element is a primitive type (string/number/boolean/null). An array of objects (such as [{"name":"x"}]) becomes an array of tables [[items]]. If your object array was mistakenly recognised as an inline array, it means the array contains non-object elements. Please check the data: ① whether the array contains mixed strings or numbers; ② whether the nesting level was broken.

Some keys are wrapped in quotes after conversion — how to remove them?

TOML allows bare keys to only contain letters, digits, underscores and hyphens ([A-Za-z0-9_-]). If a JSON key contains special characters (spaces, dots, Chinese, emoji, reserved words), the tool automatically wraps the key in double quotes to keep the TOML valid, for example {"my key": 1} becomes "my key" = 1. If your downstream tool does not accept quoted keys, please rename the JSON keys to legal characters (A-Z a-z 0-9 _ -) before conversion.

Browser lags when converting large files — what to do?

The tool is optimised for real-time conversion, but very large files (>1 MB, hundreds of thousands of lines) may still cause pressure. Recommendations: ① first use the JSON Formatter tool to check that the JSON is valid; ② convert in batches (e.g. split by top-level keys); ③ make sure your browser has enough memory; ④ for very large config files (10 MB+), consider using a command-line tool such as taplo or tomlq. This tool targets everyday configuration scenarios (KB to a few hundred KB).

Glossary

TOML
Tom's Obvious, Minimal Language — a configuration-oriented format language with concise, unambiguous syntax, the default config format for Rust Cargo, Python pyproject, and Hugo.
Table
In TOML, a named group declared with [name], equivalent to a JSON object, supporting dot-nesting such as [server.ssl].
Array of Tables
In TOML, a list of homogeneous objects declared with [[name]]; each [[name]] segment holds the fields of one object, equivalent to a JSON array of objects.
Inline Table
A syntax supported by TOML 1.0 that declares simple objects on a single line using { key = value, key = value }, suitable for unnamed flat objects.
Cargo.toml
The standard config file for Rust projects, defining package metadata, dependencies, dev-dependencies, features, and more, in TOML format.
pyproject.toml
The standard config file for Python projects (PEP 621), defining build-system, project metadata, dependencies, and tool configs (black, pytest, mypy, etc.).
TOML v1.0
The stable version of TOML officially released in 2021, which this tool strictly follows (github.com/toml-lang/toml/blob/main/toml.md).
Nested JSON Object
A JSON object that contains other objects, corresponding to TOML Table ([section]) or subtable ([a.b.c]).
TOML Escape
Special characters inside TOML strings (double quotes, backslashes, newlines, etc.) must be escaped with backslashes (\" \\ \n), and the tool handles this automatically.
Configuration File
A settings file read by an application at startup, kept separate from code for easy modification. TOML is one of the de facto standards for configuration files.

JSON to TOML Type Mapping

This tool maps JSON types to TOML types using the following rules:

JSON TypeTOML TypeTOML SyntaxNotes
stringstringkey = "value"TOML strings must use double quotes
integerintegerkey = 8080Integers have no decimal point
floatfloatkey = 3.14Floats must have a decimal point
booleanbooleankey = trueTOML only uses lowercase true / false
nullstring (empty)key = ""TOML has no null; becomes empty string
array[primitive]arraykey = ["a", "b"]Primitive arrays use inline brackets
array[object]array of tables[[items]]\nkey = valueObject arrays use [[name]] tables
objecttable[name]\nkey = valueObjects use [name] table headers

TOML String Escape Reference

Special characters that must be escaped inside TOML strings:

OriginalTOML EscapeNameExample Use Case
"\"Double QuoteNested double quotes inside strings
\\\BackslashWindows path like C:\Users
newline\nNewlineCompressing multi-line strings
tab\tTabTab-separated field values
return\rCarriage ReturnWindows CRLF line endings
\b\bBackspaceBackspace character
\f\fForm FeedForm feed character
U+0000\u0000Unicode 0Control characters must use \u escape

JSON to TOML Conversion Examples

Complex JSON inputs and their TOML outputs:

StructureExample
JSON Input{ "name": "app", "port": 8080 }
TOML Outputname = "app" port = 8080
JSON Input{ "server": { "host": "0.0.0.0", "port": 443 } }
TOML Output[server] host = "0.0.0.0" port = 443
JSON Input{ "hosts": [{"ip":"10.0.0.1"},{"ip":"10.0.0.2"}] }
TOML Output[[hosts]] ip = "10.0.0.1" [[hosts]] ip = "10.0.0.2"

Privacy & Security

This tool runs all JSON parsing, TOML generation, string escaping and file reading in your browser's local JavaScript engine. Your JSON content and the generated TOML configuration are never sent over the network to any server, and are never recorded or analysed. JSON containing database passwords, API keys, internal hostnames and other sensitive configuration can be safely converted. Local history is stored only in your own browser's localStorage, and can be deleted by closing the browser or clearing the cache.

Authoritative References