Last updated
What Is TOML?
TOML (Tom's Obvious, Minimal Language) is a configuration file format designed to be easy to read and write. It maps unambiguously to a hash table and is used by Rust's Cargo, Python's pyproject.toml, and many other tools. TOML is more readable than JSON for configuration (supports comments, multi-line strings) and less ambiguous than YAML (no implicit type coercion).
TOML Syntax Overview
# This is a TOML comment
[package]
name = "my-app"
version = "1.0.0"
authors = ["Alice <alice@example.com>"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = "1.0"
[[servers]]
host = "192.168.1.1"
port = 8080
[[servers]]
host = "192.168.1.2"
port = 8081
[database]
url = "postgres://localhost/mydb"
max_conn = 10
enabled = true
[paths]
data = "/var/data"
logs = """
/var/log/app
/var/log/error
"""
TOML vs YAML vs JSON
| Feature | TOML | YAML | JSON |
|---|---|---|---|
| Comments | Yes (#) | Yes (#) | No |
| Multi-line strings | Yes (triple quotes) | Yes (| and >) | No (escape ) |
| Type ambiguity | Low | High (Norway problem) | Low |
| Arrays of tables | [[table]] | List of maps | Array of objects |
| Dates | Native (RFC 3339) | Native | String only |