TOML to JSON: Convert Cargo.toml and pyproject.toml to JSON
TOML is the configuration language of Rust's Cargo and Python's pyproject.toml. Its type system and clear structure make it easy to read — but tooling that needs to process config data often works with JSON. This converter handles TOML's key features: typed scalar values, [tables], [[arrays of tables]], and inline values.
Unlike INI, TOML has typed values — numbers, booleans, and strings are preserved in the JSON output.
TOML's Type System
TOML infers types from the value syntax: 42 is an integer, 3.14 is a float, true/false is a boolean, "string" is a string, [1, 2, 3] is an array, and { key = val } is an inline table. These types are preserved in the JSON output, which makes TOML-to-JSON conversion lossless for most config files.
Tables and Array of Tables
[table] defines a section that becomes a JSON object. Dotted table names like [package.metadata] create nested objects. [[array_of_tables]] (double brackets) creates an array — each [[section]] header starts a new object in the array. This is how TOML represents arrays of objects (like a list of servers or build targets).
TOML vs YAML vs JSON for Config
JSON lacks comments and multi-line strings, making it awkward for config files. YAML is flexible but ambiguous (the Norway problem: 'NO' parses as false). TOML is explicit and typed, making it unambiguous. The trade-off: TOML is verbose for deeply nested structures, where YAML's indentation is more compact.
Practical Examples
Inspecting a Cargo.toml in a REST API
Parse a Rust project's Cargo.toml to extract dependency information programmatically.
- 1.Paste the Cargo.toml content
- 2.JSON output shows [package], [dependencies], and [[bin]] entries
- 3.Use the JSON in a build tool, dashboard, or dependency audit script
- 4.Parse [features] tables to understand optional feature flags
What Gets Converted
- [table] → nested JSON object
- [[array_of_tables]] → JSON array of objects
- Typed scalars: string, integer, float, boolean
- Inline arrays [1, 2, 3] → JSON arrays
- Inline tables { key = val } → JSON objects
Good Use Cases
- Reading Cargo.toml dependency graphs in tooling
- Processing pyproject.toml for Python project metadata
- Converting Hugo config.toml for static site tooling
- Inspecting TOML configs in non-TOML-aware environments
Frequently Asked Questions
What is TOML?
TOML (Tom's Obvious, Minimal Language) is a configuration format designed to be unambiguous and easy to parse. It is the default config format for Rust (Cargo.toml), used by Python (pyproject.toml), Hugo (config.toml), and many other tools. It was designed as an alternative to YAML's complexity and INI's lack of types.
How do [[array of tables]] work?
Double brackets [[section]] define an array of tables. Each [[section]] header starts a new object in the array. So two [[servers]] blocks produce an array of two server objects in the JSON output. This is TOML's way of expressing arrays of objects.
Does TOML have typed values?
Yes. TOML supports strings (quoted), integers, floats, booleans (true/false), dates, inline arrays ([]), and inline tables ({}). This converter preserves types in the JSON output — numbers become JSON numbers, booleans become JSON booleans, etc.
What TOML features are not supported?
Multi-line strings (triple-quoted across multiple lines), date/datetime values (treated as strings), dotted keys (key.sub = value), multi-line arrays ([] spanning multiple lines), and TOML 1.0 specific features are partially or not supported. Use the toml npm package or Rust's toml crate for full compliance.