TOML to JSON
Convert TOML configuration files to JSON. Supports arrays of tables, inline tables, and all TOML types.
What Is TOML?
TOML (Tom's Obvious, Minimal Language) is a configuration file format designed to be easy to read and write due to its clear, explicit semantics. Created by Tom Preston-Werner (co-founder of GitHub), TOML maps unambiguously to a hash table and is widely used in the Rust ecosystem (Cargo.toml), Python packaging (pyproject.toml), and static site generators like Hugo.
Unlike YAML, TOML is unambiguous — there is no Norway problem, no implicit type coercion, and no indentation-based structure. This makes it ideal for configuration files that humans write and machines read.
Conversion Example
TOML (Cargo.toml)
[package]
name = "my-app"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
[[bin]]
name = "server"
path = "src/main.rs"JSON result
{
"package": {
"name": "my-app",
"version": "0.1.0",
"edition": "2021"
},
"dependencies": {
"serde": { "version": "1.0", "features": ["derive"] },
"tokio": { "version": "1", "features": ["full"] }
},
"bin": [
{ "name": "server", "path": "src/main.rs" }
]
}pyproject.toml Example
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "my-package"
version = "1.0.0"
description = "A Python package"
requires-python = ">=3.10"
dependencies = [
"requests>=2.28",
"pydantic>=2.0",
]
[project.scripts]
my-cli = "my_package.cli:main"
[tool.ruff]
line-length = 100pyproject.toml is the standard configuration file for Python packages (PEP 517/518/621). It replaces setup.py, setup.cfg, and requirements.txt for modern Python projects.
TOML Type Mapping to JSON
| TOML Type | Example | JSON Type | JSON Example |
|---|---|---|---|
| String | name = "hello" | string | "hello" |
| Integer | port = 8080 | number | 8080 |
| Float | pi = 3.14159 | number | 3.14159 |
| Boolean | debug = true | boolean | true |
| Offset DateTime | dt = 1979-05-27T07:32:00Z | string | "1979-05-27T07:32:00.000Z" |
| Local DateTime | dt = 1979-05-27T07:32:00 | string | "1979-05-27T07:32:00" |
| Local Date | date = 1979-05-27 | string | "1979-05-27" |
| Local Time | time = 07:32:00 | string | "07:32:00" |
| Array | tags = ["a", "b"] | array | ["a", "b"] |
| Table | [server] | object | {"server": {}} |
| Array of Tables | [[bins]] | array | {"bins": [{...}]} |
| Inline Table | {host="localhost"} | object | {"host": "localhost"} |
Common Use Cases
- Rust Cargo.toml — package metadata, dependencies, build profiles, workspace configuration
- Python pyproject.toml — project metadata, build system, tool configuration (ruff, black, pytest)
- Hugo config.toml — static site generator configuration
- Deno deno.json — Deno runtime and tool configuration
- Converting to JSON for APIs — when you need to send TOML config data to a JSON API
- Tooling integrations — some tools require JSON input but your config is TOML