How JSON to TOML conversion works
TOML is a configuration format built for humans to read and edit. The mapping from JSON follows a few rules: flat key-value pairs stay as-is, nested objects become [table] sections, arrays of objects become [[array-of-tables]] blocks, and primitive arrays stay inline. A flat JSON object converts almost one-to-one.
{
"name": "jsonic",
"version": "1.0.0",
"private": true,
"retries": 3
}name = "jsonic"
version = "1.0.0"
private = true
retries = 3Nested objects become TOML tables
A nested JSON object becomes a TOML table declared with a [header] on its own line, followed by its key-value pairs. Deeper nesting uses dotted headers like [server.database]. A short object used as a value can also be written as an inline table on one line: server = {host = "localhost", port = 8080}.
{
"server": {
"host": "localhost",
"port": 8080
},
"database": {
"poolSize": 10
}
}[server]
host = "localhost"
port = 8080
[database]
poolSize = 10Arrays of objects become array tables
JSON arrays that contain objects map to TOML array tables, written with the double-bracket header [[name]]. Each [[name]] block adds one more object to the array — ideal for plugin lists, server instances, or route definitions that repeat.
{
"plugins": [
{ "name": "auth", "enabled": true },
{ "name": "billing", "enabled": false }
]
}[[plugins]]
name = "auth"
enabled = true
[[plugins]]
name = "billing"
enabled = falseTypes, dates, and null limitations
TOML supports strings, integers, floats, booleans, datetimes, arrays, and tables. A date held as a JSON string can be promoted to a real TOML datetime (no quotes). The two things that do not survive: JSON null (no TOML type) and mixed-type arrays, which TOML rejects because every element of an array must share one type. Drop or replace nulls before converting.
{
"created": "2026-06-17T09:30:00Z",
"tags": ["a", "b", "c"],
"theme": null
}# null dropped; date becomes a real TOML datetime
created = 2026-06-17T09:30:00Z
tags = ["a", "b", "c"]Convert JSON to TOML in code
When you need conversion in a script or build step instead of the browser tool:
# Python — tomli-w (write-only). Strip nulls first; TOML has no null.
import json, tomli_w
data = json.loads(open("data.json").read())
print(tomli_w.dumps(data))// Node.js — @iarna/toml. Root must be an object (a TOML table).
const TOML = require('@iarna/toml')
const data = require('./data.json')
console.log(TOML.stringify(data))When JSON to TOML works best (and common mistakes)
TOML suits config-like JSON: an object at the root, nested objects as sections, arrays of similarly shaped objects, no null values, and output meant to be edited by humans. It is the wrong target for arbitrary API payloads.
- Trying to convert a root JSON array — wrap it under a key first.
- Leaving
nullvalues in the input (TOML has no null). - Using mixed-type arrays like
[1, "two", true], which TOML rejects. - Expecting TOML to preserve JSON object key order as business logic.
For a step-by-step walkthrough with the full type-mapping table, see the JSON to TOML tutorial. For a similar human-friendly config format, try JSON to YAML.