Every Rust project carries a Cargo.toml manifest: the package name and version, the edition it builds with, the crates it depends on, and a stack of other settings, all written as TOML tables. Humans read that file comfortably. The scripts, dashboards and reports that want to ask questions of it, which dependencies does this project use, what version is it on, almost always speak JSON instead. Writing a TOML parser just to answer those questions is overkill. This guide converts a Cargo.toml into clean nested JSON with the free TOML to JSON Converter on Ovatly, which runs entirely in your browser, and explains exactly what the output preserves and where its limits sit.
Contents
- Quick answer
- Why a Rust manifest is worth converting
- What the structure looks like after conversion
- How to convert Cargo.toml to JSON, step by step
- Worked example: a small manifest, converted
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Open the TOML to JSON Converter, paste the contents of your Cargo.toml, and convert. Every [table] in the manifest becomes a nested JSON object under the table's name, so [package] becomes a package object and [dependencies] becomes a dependencies object whose values are the version strings exactly as written. Arrays of tables become arrays of objects, and dotted keys nest. The result is plain JSON you can hand to a script, a dashboard or a report. If the manifest uses a construct outside the converter's supported subset, the conversion stops and the error names the line number instead of guessing.
Why a Rust manifest is worth converting
Cargo.toml is the single source of truth for a Rust project. It names the package, pins its version, declares its dependencies and carries configuration for builds, features and publishing. Teams routinely want that information somewhere else: an internal dashboard listing every project's version, a script that inventories dependencies across a folder of repositories, a report for a security review asking which crates are in use.
Each of those consumers reads JSON natively. Converting the manifest once, into a structured document whose shape mirrors the original tables, is far simpler than teaching each consumer to parse TOML. And because the conversion is a faithful structural copy, you can regenerate it whenever the manifest changes and trust that the JSON still describes the same project.
What the structure looks like after conversion
The mapping is mechanical. Key and value pairs written before any header land at the top level of the JSON. Each [table] header becomes one object: everything under [package] collects into a package object, everything under [dependencies] into a dependencies object. A header with double brackets, such as [[bin]], opens an array of tables and becomes an array of objects, one per entry. Dotted keys nest inside a single line, and inline tables become nested objects.
Values keep their types, with two honest exceptions. Strings, integers, floats and booleans carry over as the same JSON types. Dependency versions are strings in the manifest, so they stay strings: the JSON holds "1.0", not the number 1.0. Dates and times, rare in a manifest, are kept as their original text, because JSON has no date type. Nothing is flattened, renamed or dropped: if a value is under [dependencies] in the TOML, it is under dependencies in the JSON.
How to convert Cargo.toml to JSON, step by step
- Open your project's Cargo.toml and copy its full contents. Work from a copy if you plan to experiment, so the real manifest stays untouched.
- Open the TOML to JSON Converter and paste the manifest into the input. The parser runs in your browser; the file never leaves your device.
- Run the conversion. If it stops, the error names the line number of the construct it cannot handle; simplify that line in your copy and convert again.
- Check the shape of the output: a package object with the name, version and edition, a dependencies object with one string per crate. Then copy the JSON into your script, dashboard or report.
Worked example: a small manifest, converted
Take a typical small manifest:
[package]
name = "log-cleaner"
version = "0.3.0"
edition = "2021"
[dependencies]
serde = "1.0"
anyhow = "1.0"
The conversion produces:
{
"package": {
"name": "log-cleaner",
"version": "0.3.0",
"edition": "2021"
},
"dependencies": {
"serde": "1.0",
"anyhow": "1.0"
}
}
Read it the way a script would. The project name lives at package.name, its version at package.version, and the dependency list is a simple object to iterate: two crates, serde and anyhow, each mapped to the version string the manifest declared. The edition stays the string "2021" because that is what the manifest holds. A dashboard can now show this project's name and version next to every other project converted the same way, and an inventory script can collect the keys of the dependencies object without understanding anything about TOML.
Limitations and honest tradeoffs
The converter works in one direction only, TOML to JSON. The JSON is a reading copy, never a replacement manifest: Cargo reads TOML, so any change belongs in Cargo.toml, followed by a fresh conversion.
It is also a subset parser. It covers the constructs manifests actually use: key and value pairs, dotted and quoted keys, tables and arrays of tables, the standard string forms, integers, floats, booleans, arrays and inline tables. A genuinely unusual construct outside that subset stops the conversion completely, with the line number named and no partial output. That is deliberate: a dashboard quietly built on half a manifest is worse than no dashboard. Dates and times, if a manifest carries any, arrive as strings, and very large integers are preserved as digit strings rather than rounded.
Common mistakes
- Editing the JSON and expecting the project to change. Cargo never reads the JSON. Edit Cargo.toml, then convert again.
- Treating version values as numbers. They are strings, in the manifest and in the output. Code that compares them should compare them as version strings, not floats.
- Assuming a stopped conversion means a broken manifest. Cargo accepts all of TOML; the converter covers a subset. A stop usually means one unusual line, and the error tells you which.
- Converting once and forgetting the copy goes stale. The JSON describes the manifest at conversion time. Regenerate it whenever dependencies or versions change.
- Flattening the output by hand. The nesting is the value: it mirrors the tables, so queries stay predictable across projects.
FAQs
Can this tool convert JSON back into TOML? No. The converter works in one direction only, from TOML to JSON. If the manifest needs changes afterwards, edit the original Cargo.toml and convert again, so the TOML stays the source of truth.
Why do dependency versions stay strings in the JSON? Because they are strings in the manifest. A version is a label, not a quantity, and the converter preserves it exactly instead of turning it into a number that would lose characters such as a trailing zero.
What happens if my Cargo.toml uses something the converter does not support? The conversion stops and the error names the line number of the problem. No partial JSON is produced. Fix or simplify that line in a copy of the manifest and convert again.
Is my Cargo.toml uploaded to a server? No. The parser runs in your browser, so the manifest never leaves your device. That matters for private projects whose dependency lists you would rather not send anywhere.
What can I do with the JSON once I have it? Feed it to anything that reads JSON: a script listing a project's dependencies, a dashboard showing project metadata, or a report comparing versions across several Rust projects. The nested structure mirrors the manifest tables, so queries follow the same paths.
Conclusion
Converting Cargo.toml to JSON is a small job with a tidy result: the manifest's tables become nested objects, its dependency versions stay exactly the strings the author wrote, and the output drops straight into the scripts, dashboards and reports that asked for it. The TOML to JSON Converter does it locally in your browser, and stops honestly, line number attached, if a manifest uses something outside its subset. If your conversions ever produce output that looks wrong rather than merely new, our guide to TOML to JSON mistakes with tables and date values explains the four usual causes. More guides in this series live in our Data and JSON Tools guides.
References
- The Cargo Book, on the manifest format and its tables: https://doc.rust-lang.org/cargo/reference/manifest.html
- TOML v1.0.0 specification, on tables, keys and value types: https://toml.io/en/v1.0.0