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

json
{
  "server": {
    "host": "localhost",
    "port": 8080,
    "debug": true
  },
  "database": {
    "url": "postgresql://localhost/mydb",
    "max_connections": 10
  }
}

TOML output

toml
[server]
host = "localhost"
port = 8080
debug = true

[database]
url = "postgresql://localhost/mydb"
max_connections = 10

JSON to TOML Type Mapping

JSON TypeJSON ExampleTOML TypeTOML Example
string"hello"Stringname = "hello"
number (integer)8080Integerport = 8080
number (float)3.14Floatpi = 3.14
booleantrueBooleandebug = true
object{"key": "val"}Table[section]
array of objects[{...}]Array of Tables[[items]]
array of primitives[1,2,3]Arraynums = [1, 2, 3]
nullnullN/ANot 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:

javascript
// 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 needed

Use 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

Frequently Asked Questions

The most common reasons are: (1) the JSON root is an array — TOML requires an object at the root; (2) the JSON contains null values — TOML has no null type; (3) arrays of mixed types — TOML v1.0 arrays must contain elements of the same type.

Nested JSON objects become TOML sections (tables). For example, { "server": { "host": "localhost" } } becomes [server] followed by host = "localhost" on the next line.

Yes, if you have a JSON array of objects like { "bins": [{"name": "a"}, {"name": "b"}] }, the converter will produce [[bins]] notation in TOML for each element.

Yes — use JSONKit's TOML to JSON converter for the reverse direction.

Yes, TOML supports # line comments. The converter cannot add comments (JSON has no comment concept), but you can manually add # comments to the generated TOML output to document your configuration.

Related Tools