TOML ↔ JSON Converter
Convert between TOML and JSON formats and validate TOML syntax.
About this tool
TOML (Tom's Obvious, Minimal Language) and JSON are two popular configuration and data formats used across software development. TOML is human-friendly and commonly found in Rust projects, Python tools, and modern application configs, while JSON is the universal standard for data interchange in web APIs and web applications. Converting between these formats is essential when migrating projects, sharing configurations across different systems, or working with tools that require a specific format.
To use this converter, simply paste your TOML or JSON content into the input area, and the tool automatically detects the format and converts it to the other. It also validates your input for syntax errors, reporting any issues before conversion. Use this tool when integrating third-party libraries, managing environment configurations, standardizing data for APIs, or ensuring your config files are syntactically correct.
The converter handles nested structures, arrays, inline tables, and all TOML and JSON data types including dates and floating-point numbers. Keep in mind that TOML comments are not preserved during conversion—if preserving comments is critical, consider version control or separate documentation. This tool is ideal for developers, DevOps engineers, and anyone working with multiple config formats.
Frequently Asked Questions
Code Implementation
# Python 3.11+ has tomllib built-in (read-only)
# For older versions: pip install tomli
# For writing: pip install tomli-w
import tomllib # Python 3.11+
# import tomli as tomllib # Python < 3.11
toml_text = """
[package]
name = "my-app"
version = "1.0.0"
authors = ["Alice <alice@example.com>"]
[dependencies]
requests = ">=2.28.0"
flask = { version = ">=3.0", optional = true }
[[server]]
host = "web1.example.com"
port = 8080
[[server]]
host = "web2.example.com"
port = 8081
"""
# Parse TOML string
data = tomllib.loads(toml_text)
print(data["package"]["name"]) # my-app
print(data["dependencies"]) # {'requests': '>=2.28.0', ...}
print(data["server"]) # [{'host': 'web1...', 'port': 8080}, ...]
# Parse from file
with open("pyproject.toml", "rb") as f: # Must open in binary mode!
config = tomllib.load(f)
# Writing TOML (requires tomli-w or tomllib doesn't support write)
# pip install tomli-w
import tomli_w
output = tomli_w.dumps({"key": "value", "count": 42})
print(output)
# key = "value"
# count = 42Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.