ToolDeck

JSON to TOML

Convert JSON to TOML format

Try an example

JSON Input

TOML Output

Runs locally · Safe to paste secrets
TOML output will appear here…

What Is JSON to TOML Conversion?

JSON to TOML conversion transforms data from JavaScript Object Notation into Tom's Obvious Minimal Language. JSON uses curly braces, square brackets, and quoted keys to represent structured data. TOML uses a flat key-value syntax with section headers (called tables) that reads like an INI file but with strict typing. TOML was designed specifically for configuration files where human readability matters more than machine interchange.

TOML has become the default configuration format for Rust (Cargo.toml), Python packaging (pyproject.toml), Hugo static sites, Netlify deployment settings, and many CLI tools. When your source data exists as JSON — from an API response, an exported config, or a generated file — and your target system expects TOML, you need a converter that maps JSON objects to TOML tables, JSON arrays to TOML arrays, and preserves every data type accurately.

Converting JSON to TOML online is the fastest way to generate valid TOML from existing JSON data. The conversion handles type mapping automatically: JSON strings become TOML strings, JSON numbers become TOML integers or floats, JSON booleans map directly, and JSON objects become TOML tables. The one exception is null — TOML has no null type, so null values are either omitted or converted to empty strings depending on the converter.

Why Use This JSON to TOML Converter?

TOML is what config files expect; JSON is what APIs and tools produce. This converter bridges the gap so you can move data between the two formats without manual rewriting.

Instant Conversion
Paste JSON and get TOML output immediately. The conversion runs as you type with no server round-trips or file uploads.
🔒
Privacy-First Processing
All conversion happens locally in your browser. Configuration secrets, API keys, and database credentials in your JSON never leave your device.
🔀
Full Structure Support
Nested objects become TOML tables, arrays of objects become arrays of tables ([[table]]), and mixed-type arrays are handled correctly.
📋
No Account Required
Open the page and convert. No sign-up, no extension to install, no CLI dependency. Works on any device with a modern browser.

JSON to TOML Use Cases

Rust Project Configuration
Cargo.toml defines dependencies, features, and build settings for Rust projects. Convert JSON dependency lists or generated configs into Cargo.toml format directly.
Python Packaging (pyproject.toml)
PEP 518 and PEP 621 standardized pyproject.toml as the Python project metadata file. Convert existing JSON package metadata into the required TOML structure.
Static Site Configuration
Hugo, Netlify, and other static site generators use TOML config files. When migrating from a JSON-based setup or generating config programmatically, convert the output to TOML.
DevOps & Infrastructure
Tools like Terraform (for certain providers), Consul, and various container runtimes accept TOML configuration. Convert JSON-exported settings to TOML without retyping values.
API Response to Config File
REST APIs return JSON. When you need to use that data as a TOML configuration — for example, feature flags or environment settings — paste the response and get valid TOML.
Learning TOML Syntax
Students and developers new to TOML can paste familiar JSON structures and see the equivalent TOML output.

JSON vs TOML Comparison

JSON and TOML overlap in capability but differ in syntax, type support, and intended use. This table shows the differences that affect conversion.

FeatureJSONTOML
SyntaxBraces, brackets, colons, commasKey = value, [table], [[array]]
CommentsNot allowed (RFC 8259)Supported with #
Data typesstring, number, boolean, null, object, arraystring, integer, float, boolean, datetime, array, table
null supportNative (null)No null type — omit the key or use empty string
Nested objectsUnlimited nesting depthDotted keys or [table.subtable] headers
Arrays of objectsArray of objects with [][[array-of-tables]] syntax
ReadabilityModerate — bracket-heavy at depthHigh — flat key-value pairs
SpecRFC 8259 / ECMA-404TOML v1.0.0 (toml.io)

TOML Conversion Gotchas

TOML has rules that differ from JSON in ways that affect conversion output. These four issues cause the most confusion.

No null Type in TOML
JSON supports null as a first-class value. TOML has no null type at all. When converting, null values must be handled — either by omitting the key entirely, using an empty string, or choosing a sentinel value. This means a round-trip from JSON to TOML and back may not reproduce the original null values.
Heterogeneous Arrays Are Restricted
JSON arrays can mix types freely: [1, "two", true]. TOML v1.0.0 requires all elements in an array to be the same type. If your JSON contains mixed-type arrays, the converter must either stringify all elements or raise an error. Check your output when source arrays contain mixed types.
Deeply Nested Objects Become Verbose
JSON handles deep nesting naturally with nested braces. TOML uses dotted keys or chained [table.subtable.key] headers, which can become long for deeply nested structures. The output is valid but less compact than the JSON original.
Key Naming Restrictions
TOML bare keys can only contain ASCII letters, digits, dashes, and underscores. JSON keys can be any string. If your JSON has keys with spaces, dots, or special characters, those keys must be quoted in the TOML output. Most converters handle this automatically, but verify the output if your keys contain unusual characters.

Code Examples

Converting JSON to TOML programmatically requires a TOML serialization library in most languages. Standard libraries parse JSON; TOML output needs a dedicated package.

JavaScript (Node.js)
import { stringify } from '@iarna/toml'

const json = '{"title":"My App","database":{"host":"localhost","port":5432}}'
const obj = JSON.parse(json)
const toml = stringify(obj)
console.log(toml)
// → title = "My App"
// →
// → [database]
// → host = "localhost"
// → port = 5432
Python
import json
import tomli_w  # pip install tomli_w

json_str = '{"title": "My App", "database": {"host": "localhost", "port": 5432}}'
data = json.loads(json_str)
toml_str = tomli_w.dumps(data)
print(toml_str)
# → title = "My App"
# →
# → [database]
# → host = "localhost"
# → port = 5432
Go
package main

import (
    "encoding/json"
    "fmt"
    "github.com/pelletier/go-toml/v2"
)

func main() {
    jsonStr := `{"title":"My App","database":{"host":"localhost","port":5432}}`
    var data map[string]interface{}
    json.Unmarshal([]byte(jsonStr), &data)

    tomlBytes, _ := toml.Marshal(data)
    fmt.Println(string(tomlBytes))
    // → title = 'My App'
    // →
    // → [database]
    // → host = 'localhost'
    // → port = 5432
}
CLI (yj / remarshal)
# Using yj (https://github.com/sclevine/yj)
echo '{"title":"My App","port":3000}' | yj -jt
# → title = "My App"
# → port = 3000

# Using remarshal (pip install remarshal)
echo '{"title":"My App","port":3000}' | remarshal -if json -of toml
# → title = "My App"
# → port = 3000

Frequently Asked Questions

Is JSON to TOML conversion lossless?
For most data, yes. Strings, integers, floats, booleans, objects, and arrays all have direct TOML equivalents. The two exceptions are null (TOML has no null type, so null values are omitted or replaced) and mixed-type arrays (TOML requires uniform array element types). If your JSON avoids these two patterns, the conversion is fully lossless.
What happens to JSON null values in TOML?
TOML does not have a null type. Converters typically omit keys with null values from the output, since there is no way to represent "key exists but has no value" in TOML. Some converters let you choose to use an empty string instead. Check your output if null values carry meaning in your data.
Can TOML represent nested JSON objects?
Yes. JSON objects become TOML tables. A nested object like {"database": {"host": "localhost"}} converts to a [database] table header with host = "localhost" beneath it. Arbitrary nesting depth is supported through dotted keys or nested table headers.
Why do Rust and Python use TOML instead of JSON?
TOML supports comments, which are essential for documenting configuration choices. It also produces cleaner output for flat key-value settings, which make up the bulk of package metadata. JSON forbids comments (RFC 8259), making it harder to maintain as a human-edited config format.
How does TOML handle dates and times?
TOML has native datetime types: offset datetime (2024-01-15T10:30:00Z), local datetime, local date, and local time. JSON has no date type — dates are stored as strings. When converting JSON to TOML, date-like strings remain strings unless the converter explicitly detects and converts ISO 8601 patterns.
Is it safe to paste secrets and credentials into this tool?
Yes. The conversion runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by opening your browser's developer tools, switching to the Network tab, and confirming that no requests are made during conversion.
What TOML version does the output follow?
The output follows TOML v1.0.0, which was released in January 2021 and is the current stable specification. This version requires uniform array types, supports dotted keys, and defines the datetime format. The spec is maintained at toml.io.