What is TOML?
TOML (Tom's Obvious Minimal Language) is a configuration file format designed to be human-readable and unambiguous. It is the primary config format for Rust (Cargo.toml), Python (pyproject.toml), and Hugo static sites.
JSON vs TOML: Key Differences
- Comments: TOML supports
# hash comments; JSON does not - Dates: TOML has a native datetime type; JSON uses strings
- Readability: TOML uses flat dot-notation sections; JSON uses nested braces
- Use case: JSON for APIs and data; TOML for configuration files
When to Use JSON to TOML Conversion
- Migrating a Node.js
package.jsonconfig topyproject.toml - Building a Rust package and needing to write
Cargo.tomlfrom JSON specs - Converting Hugo or Zola site configuration between formats
json
// JSON Input
{
"package": {
"name": "my-lib",
"version": "0.1.0",
"authors": ["Alice <alice@example.com>"],
"edition": "2021"
},
"dependencies": {
"serde": { "version": "1.0", "features": ["derive"] }
}
}
# TOML Output (Cargo.toml style)
[package]
name = "my-lib"
version = "0.1.0"
authors = ["Alice <alice@example.com>"]
edition = "2021"
[dependencies.serde]
version = "1.0"
features = ["derive"]