JSON to TOML
Convert JSON objects to TOML configuration format. Root must be an object (not an array).
Converting JSON to TOML
JSON and TOML both represent structured data, but TOML is designed specifically for configuration files written by humans. Converting JSON to TOML is useful when migrating from a JSON configuration file to a more readable TOML format, or when generating Cargo.toml, pyproject.toml, or Hugo config files programmatically.
The converter maps JSON objects to TOML tables, JSON arrays to TOML arrays, and preserves all JSON primitive types (strings, numbers, booleans). Note that TOML requires the root to be a table — a root-level JSON array will produce an error.
Conversion Example
JSON input
{
"server": {
"host": "localhost",
"port": 8080,
"debug": true
},
"database": {
"url": "postgresql://localhost/mydb",
"max_connections": 10
}
}TOML output
[server]
host = "localhost"
port = 8080
debug = true
[database]
url = "postgresql://localhost/mydb"
max_connections = 10JSON to TOML Type Mapping
| JSON Type | JSON Example | TOML Type | TOML Example |
|---|---|---|---|
| string | "hello" | String | name = "hello" |
| number (integer) | 8080 | Integer | port = 8080 |
| number (float) | 3.14 | Float | pi = 3.14 |
| boolean | true | Boolean | debug = true |
| object | {"key": "val"} | Table | [section] |
| array of objects | [{...}] | Array of Tables | [[items]] |
| array of primitives | [1,2,3] | Array | nums = [1, 2, 3] |
| null | null | N/A | Not supported in TOML |
Limitations
Not all JSON structures have a direct TOML equivalent. The following will cause an error or may not convert as expected:
// These JSON structures CANNOT be represented in TOML:
// 1. Root-level array (TOML root must be a table)
["item1", "item2", "item3"]
// 2. Array of mixed types (TOML arrays must be homogeneous in TOML v0.5)
{ "mixed": [1, "two", true] }
// 3. null values (TOML has no null type)
{ "value": null }
// 4. Keys with characters invalid in TOML (use bare keys or quoted keys)
// smol-toml will quote keys as neededUse Cases
- Migrating package.json → Cargo.toml — convert package metadata from npm to Rust format
- Generating config files — programmatically generate TOML configs from JSON data
- Hugo static sites — convert JSON settings to Hugo's config.toml format
- pyproject.toml generation — build TOML configuration from a JSON template
- Exploring TOML syntax — use familiar JSON to learn how TOML represents data