FormatForge

JSON to TOML Converter

Convert JSON to TOML format instantly. Perfect for Rust Cargo.toml, Python pyproject.toml, and other configuration files. Free, secure, and works entirely in your browser.

JSON
TOML

Drop a file here or click to upload

Supports .json files

Understanding JSON and TOML

JSON (JavaScript Object Notation) is the most widely used data-interchange format on the web. It represents data as nested key-value pairs, arrays, and primitive values (strings, numbers, booleans, and null). JSON is natively supported by JavaScript and has mature parsing libraries in every major programming language. Its flexibility makes it suitable for APIs, databases, and configuration files alike. For a comprehensive overview of JSON syntax, data types, and validation rules, visit our JSON guide.

TOML (Tom's Obvious Minimal Language) is a configuration file format designed to be easy to read and write thanks to its clear, minimal syntax. Created by Tom Preston-Werner (co-founder of GitHub), TOML maps unambiguously to a hash table and is intended to be parsed into data structures in a wide range of languages. TOML is the standard configuration format for Rust projects (Cargo.toml), Python packaging (pyproject.toml), Hugo static sites, Netlify deployments, and many other tools. Unlike JSON, TOML supports comments, has native date/time types, and uses sections (tables) that make hierarchical configuration intuitive. To learn more about TOML syntax, tables, and array of tables, see our TOML guide.

Converting JSON to TOML bridges the gap between a general-purpose data format and a purpose-built configuration format. While JSON is excellent for machine-to-machine communication, TOML is optimized for human readability in configuration scenarios. This converter handles the structural translation automatically, mapping JSON objects to TOML tables and arrays of objects to TOML arrays of tables.

Why Convert JSON to TOML?

While JSON is versatile, there are many situations where TOML is the expected or preferred format. Here are the most common real-world reasons to convert JSON to TOML:

  • Creating Rust Cargo.toml from JSON package metadata. Rust's package manager, Cargo, requires a Cargo.toml manifest file. If you have package metadata stored in JSON (from a registry API, a CI pipeline, or a code generator), converting it to TOML lets you produce a valid Cargo manifest directly.
  • Generating Python pyproject.toml files. The Python packaging ecosystem has adopted pyproject.toml as the standard for build configuration (PEP 518, PEP 621). If your tooling outputs JSON, you need to convert it to TOML to create or update pyproject.toml.
  • Configuring Hugo static sites. Hugo supports JSON, YAML, and TOML for site configuration, but TOML is the default and most commonly documented format. Converting your existing JSON config to TOML aligns with Hugo community conventions and examples.
  • Setting up Netlify or Cloudflare Pages deployments. Services like Netlify use netlify.toml for build and redirect configuration. If you generate deployment settings programmatically as JSON, converting to TOML produces a ready-to-commit config file.
  • Improving readability of configuration files. TOML supports comments and has a cleaner syntax for nested sections compared to JSON. Converting a complex JSON config to TOML makes it easier for team members to review, edit, and maintain the configuration by hand.

How the Conversion Works

The converter follows a structured process to transform your JSON data into well-formed TOML output:

  1. Parse and validate the input JSON to ensure it is syntactically correct.
  2. Check the root type. TOML requires the root to be an object (table). If the root is an array, it is wrapped in an items key to produce a valid TOML document.
  3. Map JSON objects to TOML tables. Each nested object becomes a [table] section with its own key-value pairs beneath it.
  4. Map arrays of objects to TOML arrays of tables. These use the [[table]] double-bracket syntax, which is TOML's way of representing repeated structured entries.
  5. Convert primitive values to their TOML equivalents: strings remain quoted, numbers and booleans are written without quotes, and null values are omitted.
  6. Output the formatted TOML with proper indentation and section ordering.

The table below summarizes how each JSON construct maps to its TOML equivalent:

JSON ConstructTOML Equivalent
{"key": "value"}key = "value"
{"count": 42}count = 42
{"enabled": true}enabled = true
{"db": {"host": "localhost"}}[db] table with host = "localhost"
{"tags": ["a", "b"]}tags = ["a", "b"]
{"items": [{"id": 1}, {"id": 2}]}[[items]] array of tables
{"value": null}Key omitted (TOML has no null)

Before and After Example

Below is a practical example showing a JSON package configuration being converted to a TOML format similar to what you would find in a Cargo.toml or pyproject.toml file.

Input JSON

{
  "package": {
    "name": "my-app",
    "version": "1.2.0",
    "authors": [
      "Alice <alice@example.com>",
      "Bob <bob@example.com>"
    ],
    "description": "A sample application"
  },
  "dependencies": [
    {
      "name": "serde",
      "version": "1.0",
      "features": ["derive"]
    },
    {
      "name": "tokio",
      "version": "1.28",
      "features": ["full"]
    }
  ],
  "build": {
    "optimize": true,
    "target": "release"
  }
}

Output TOML

[package]
name = "my-app"
version = "1.2.0"
authors = [
  "Alice <alice@example.com>",
  "Bob <bob@example.com>",
]
description = "A sample application"

[[dependencies]]
name = "serde"
version = "1.0"
features = ["derive"]

[[dependencies]]
name = "tokio"
version = "1.28"
features = ["full"]

[build]
optimize = true
target = "release"

Notice how the nested package object became a [package] table, the dependencies array of objects became [[dependencies]] array of tables (each entry gets its own double-bracket section), and primitive arrays like authors and features remained as inline TOML arrays. The build object became another [build] table with its key-value pairs.

Tips and Best Practices

Ensure your JSON root is an object

TOML requires the document root to be a table (object). If your JSON starts with an array like [1, 2, 3] or a string literal, the converter will wrap it in an items key to produce valid TOML. For the cleanest output, restructure your JSON to have an object at the root before converting.

Handle null values before converting

Since TOML has no null type, any JSON null values will be omitted or converted to empty strings. If null has semantic meaning in your data (for example, "not set" vs "empty string"), consider replacing nulls with a sentinel value like "N/A" or removing those keys entirely before conversion.

Keep arrays homogeneous

TOML requires all elements in an array to be the same type. A JSON array like [1, "two", true] is valid JSON but invalid TOML. Before converting, ensure your arrays contain elements of a single type, or restructure mixed arrays into separate keys.

Leverage TOML comments after conversion

One of TOML's biggest advantages over JSON is comment support. After converting your JSON config to TOML, take the opportunity to add descriptive comments (lines starting with #) explaining each section and key. This makes the configuration far more maintainable for your team.

Validate the output for your target tool

Different tools expect specific TOML structures. A valid Cargo.toml needs [package] with name, version, and edition fields. A pyproject.toml needs [build-system] and [project] sections. After conversion, verify that the output matches the schema your target tool expects.

Use JSONPath to extract a subset before converting

If your JSON contains a large API response but you only need the configuration section, use FormatForge's JSONPath filter to extract the relevant portion first. For example, $.config or $.settings can pull just the nested object you want to convert to TOML.

Related Tools

Explore other converters and resources that complement JSON-to-TOML conversion:

How to Convert JSON to TOML

  1. Paste your JSON data in the input area, or upload a JSON file
  2. Click the "Convert" button
  3. View the converted TOML output instantly
  4. Copy the result or download it as a file

Features

  • 100% client-side - your data never leaves your browser
  • No login or registration required
  • Instant conversion with real-time preview
  • Supports file upload and drag-and-drop
  • Download converted files directly
  • Works on mobile and desktop

Frequently Asked Questions

How does JSON to TOML conversion work?

The converter parses your JSON data and transforms it into TOML syntax. JSON objects become TOML tables, JSON arrays of objects become TOML arrays of tables (using the [[table]] syntax), and primitive values are converted to their TOML equivalents such as strings, integers, floats, and booleans.

Why convert JSON to TOML?

TOML is specifically designed to be a human-friendly configuration file format. It is used by Rust's Cargo (Cargo.toml), Python's packaging ecosystem (pyproject.toml), Hugo static site generator, and many other tools. If you have configuration data in JSON, converting it to TOML makes it easier to read, edit by hand, and maintain over time.

What are the limitations of converting JSON to TOML?

TOML requires the root value to be an object (table), so a JSON array or primitive at the root level will be wrapped in an 'items' key. TOML also has no null type, so JSON null values are either omitted or converted to empty strings. Additionally, TOML does not support mixed-type arrays, so arrays containing different types may need adjustment.

How are JSON null values handled in TOML?

TOML does not have a null data type. When converting JSON to TOML, null values are either omitted from the output or converted to empty strings, depending on context. If a key's value is null and it appears in a table, it will typically be left out to produce valid TOML.

Can I convert nested JSON objects to TOML?

Yes. Nested JSON objects are converted to TOML tables using the [table] syntax. For example, a JSON object {"database": {"host": "localhost"}} becomes a [database] section in TOML with host = "localhost" beneath it. Deeply nested objects create dotted table headers like [database.connection].

Does TOML support date and time values?

Yes, TOML has native support for date-time, local date, local time, and local date-time types. However, JSON does not have dedicated date types — dates are typically stored as strings. If your JSON contains ISO 8601 date strings, they remain as quoted strings in TOML unless you manually edit them to use TOML's native date syntax.

Is my data secure during conversion?

Yes, all conversion happens directly in your browser using client-side JavaScript. Your data is never sent to any server, stored in any database, or logged anywhere. You can even use this tool offline once the page has loaded.

What is the maximum file size I can convert?

Since the conversion runs entirely in your browser, performance depends on your device's memory and processing power. JSON files up to 5 MB typically convert instantly. For very large files, consider splitting them into smaller sections or using a command-line tool for batch processing.