Data Format Converter · Tutorial
How to read a pyproject.toml file as JSON
5 min readbeginnerUpdated
A pyproject.toml holds a Python project's name, version, dependencies and settings for tools like Ruff and pytest. This tutorial converts one to JSON, explains how tables such as [tool.pytest.ini_options] turn into nested objects, and shows how to use the result in a script or CI step.
What you need
- The Data Converter, set to TOML → JSON
- A
pyproject.tomlfile, or the sample from the Try it button
Steps
Paste the file
Paste the contents of
pyproject.tomlinto the left box, or open the file with the file picker. The JSON appears on the right straight away.See how the tables nest
Each table name in square brackets is a path.
[project.optional-dependencies]puts aoptional-dependenciesobject insideproject, and[tool.pytest.ini_options]createstool, thenpytest, thenini_options.[tool.pytest.ini_options] addopts = "-q" "tool": { "pytest": { "ini_options": { "addopts": "-q" } } }Find the values you need
Dependencies are now a plain array at
project.dependencies, and the Ruff line length is the number 100 attool.ruff.line-length. Keys keep their original spelling, dashes included.Use the JSON elsewhere
Press Copy or Download. In a script you can read a value with a JSON tool, for example
jq -r '.project.version' converted.jsonprints1.4.0. This is handy in CI steps that need the version number for a release tag.Fix errors if the file is broken
If the message shows an error, such as a duplicate key, it names the line and column. Fix it in the left box. The same mistake would also stop
pip installor your build tool.
Try it yourself
Opens the Data Format Converter with this tutorial's sample loaded.
Common mistakes
- Expecting keys with dashes to be renamed
requires-pythonstaysrequires-python. In JavaScript you needdata.project["requires-python"].- Declaring the same table twice
- TOML does not allow two
[project]headers. Merge their keys under one header. - Unquoted strings
- Unlike INI or YAML, TOML needs quotes around text.
name = bento-toolsis an error; writename = "bento-tools".
Next steps
Go back to the Data Format Converter, or keep going with one of these:
FAQ
Does it work for Cargo.toml too?
Yes. Any valid TOML file converts, including Cargo.toml, Hugo and Netlify configs.
Can I convert the JSON back to TOML?
Yes, with JSON → TOML in the Data Converter. Comments are not restored, so keep the original file.