FormatForge

TOML to JSON Converter

Convert TOML to JSON format instantly. Transform Cargo.toml, pyproject.toml, and other TOML files for use with APIs and applications. Free, secure, and works entirely in your browser.

TOML
JSON

Drop a file here or click to upload

Supports .toml files

Understanding TOML and JSON

TOML (Tom's Obvious Minimal Language) is a configuration file format created by Tom Preston-Werner that prioritizes human readability. It uses a clear, INI-like syntax with sections called tables, supports comments with the # character, and includes native data types for dates, times, integers, floats, booleans, strings, arrays, and tables. TOML is the standard configuration format for Rust (Cargo.toml), Python packaging (pyproject.toml), Hugo static sites, Netlify deployments, and many other developer tools. Its explicit structure makes it easy to read and edit by hand while remaining unambiguous for machine parsing. For a detailed exploration of TOML syntax, table types, and best practices, visit our TOML guide.

JSON (JavaScript Object Notation) is the most widely used data-interchange format in software development. It represents data as nested objects (key-value maps), arrays, strings, numbers, booleans, and null. JSON is natively understood by JavaScript and has parsing libraries in every major programming language. It is the default format for REST APIs, NoSQL databases like MongoDB, configuration files for tools like package.json and tsconfig.json, and data exchange between microservices. To learn more about JSON syntax, valid data types, and validation, see our JSON guide.

Converting TOML to JSON unlocks the massive ecosystem of JSON-compatible tools, libraries, and APIs. While TOML is excellent for human-authored configuration, JSON is the format that machines, APIs, and most programming frameworks consume natively. This converter bridges that gap, preserving all your data while translating it into a universally interoperable format.

Why Convert TOML to JSON?

TOML is optimized for human editing, but there are many scenarios where JSON is required or preferred. Here are the most common real-world reasons to convert TOML to JSON:

  • Processing Cargo.toml programmatically. Rust's Cargo manifest contains package metadata, dependencies, and build settings. Converting Cargo.toml to JSON makes it easy to analyze dependency trees, extract version numbers, or build custom CI/CD dashboards using standard JSON processing tools like jq or JavaScript.
  • Reading pyproject.toml in JavaScript tooling. If you are building Node.js-based development tools that need to understand Python project configuration, converting pyproject.toml to JSON lets you parse it with native JSON.parse() without needing a TOML parsing library in your JavaScript stack.
  • Importing TOML configs into web applications. Web applications and Node.js servers overwhelmingly use JSON for configuration. If you receive TOML configuration files from collaborators or upstream tools, converting them to JSON integrates seamlessly with frameworks like Next.js, Express, or Vite.
  • Sending configuration data over APIs. REST and GraphQL APIs expect JSON payloads. If your configuration is authored in TOML but needs to be submitted to an API endpoint, converting to JSON is a necessary step in the data pipeline.
  • Comparing and diffing configurations. Many diff and merge tools have better support for JSON than TOML. Converting TOML files to JSON can make it easier to compare configurations across environments (development, staging, production) using standard JSON diff utilities.

How the Conversion Works

The converter uses a standards-compliant TOML parser to transform your input into well-formed JSON output. Here is the step-by-step process:

  1. Parse the TOML input into an in-memory data structure, validating syntax and checking for errors such as duplicate keys or invalid table definitions.
  2. Convert TOML tables to JSON objects. Each [table] section becomes a nested JSON object with its keys and values.
  3. Convert TOML arrays of tables to JSON arrays. Each [[table]] entry becomes an element in a JSON array of objects.
  4. Map TOML data types to JSON equivalents. Strings, integers, floats, and booleans map directly. Dates and times are serialized as ISO 8601 strings. Inline tables become JSON objects.
  5. Discard comments. TOML comments (#) have no JSON equivalent and are removed during conversion.
  6. Format the output as pretty-printed JSON with consistent indentation for readability, or as minified JSON if the compact option is selected.

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

TOML ConstructJSON Equivalent
key = "value"{"key": "value"}
count = 42{"count": 42}
enabled = true{"enabled": true}
[database] table{"database": {...}} nested object
tags = ["a", "b"]{"tags": ["a", "b"]}
[[dependencies]] array of tables{"dependencies": [{...}, {...}]}
created = 2024-01-15{"created": "2024-01-15"} (ISO string)
point = {x = 1, y = 2} (inline table){"point": {"x": 1, "y": 2}}

Before and After Example

Below is a practical example showing a Cargo.toml-style configuration file and the resulting JSON output. Notice how TOML tables, arrays of tables, and comments are handled in the conversion.

Input TOML

# Package metadata
[package]
name = "my-web-server"
version = "0.3.1"
edition = "2021"
authors = [
  "Alice <alice@example.com>",
  "Bob <bob@example.com>",
]

# Server configuration
[server]
host = "0.0.0.0"
port = 8080
debug = false

# Dependencies
[[dependencies]]
name = "actix-web"
version = "4.4"
features = ["openssl"]

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

[build]
target-dir = "dist"
release = true

Output JSON

{
  "package": {
    "name": "my-web-server",
    "version": "0.3.1",
    "edition": "2021",
    "authors": [
      "Alice <alice@example.com>",
      "Bob <bob@example.com>"
    ]
  },
  "server": {
    "host": "0.0.0.0",
    "port": 8080,
    "debug": false
  },
  "dependencies": [
    {
      "name": "actix-web",
      "version": "4.4",
      "features": ["openssl"]
    },
    {
      "name": "serde",
      "version": "1.0",
      "features": ["derive"]
    }
  ],
  "build": {
    "target-dir": "dist",
    "release": true
  }
}

Notice how the [package] and [server] tables became nested JSON objects, the [[dependencies]] array of tables became a JSON array containing two objects, and the TOML comments (lines starting with #) were discarded since JSON has no comment syntax. All primitive values -- strings, integers, and booleans -- mapped directly to their JSON equivalents.

Tips and Best Practices

Preserve important comments separately

TOML comments are lost during conversion to JSON. If your TOML file contains important notes, documentation, or explanations in comments, save them separately before converting. You could also consider adding a "_comments" or "_notes" key in the resulting JSON to retain that context.

Be aware of date type changes

TOML has native date, time, and date-time types that are converted to ISO 8601 strings in JSON. If you plan to parse these dates programmatically, remember that they are now strings and will need to be parsed with new Date() in JavaScript or equivalent date-parsing functions in other languages.

Validate your TOML syntax first

Common TOML errors include missing closing quotes, incorrect table nesting, duplicate keys within the same table, and mixing inline tables with standard tables for the same path. FormatForge's error highlighting will pinpoint the exact line and column where parsing fails, helping you fix issues quickly.

Use minified output for API payloads

If you are converting TOML to JSON to send as an API request body, toggle the minify option to remove unnecessary whitespace. This reduces the payload size and is the standard format for HTTP request bodies. Use the pretty-printed format only for debugging and human inspection.

Check for integer overflow in large numbers

TOML supports 64-bit integers, but JSON numbers in JavaScript are IEEE 754 doubles, which can only safely represent integers up to 2^53. If your TOML contains very large integer values, verify that they are preserved accurately after conversion. For critical precision, consider converting them to strings.

Understand inline vs standard table equivalence

TOML allows both [server] standard tables and server = {host = "localhost", port = 8080} inline tables. Both produce identical JSON objects. If you see unexpected nesting in the output, it may be because an inline table was used where you expected a flat key-value pair. Both forms are semantically equivalent.

Related Tools

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

How to Convert TOML to JSON

  1. Paste your TOML data in the input area, or upload a TOML file
  2. Click the "Convert" button
  3. View the converted JSON 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 TOML to JSON conversion work?

The converter parses your TOML data using a compliant parser and transforms it into equivalent JSON syntax. TOML tables become JSON objects, TOML arrays of tables become JSON arrays of objects, and all data types including strings, integers, floats, booleans, and dates are converted to their JSON equivalents.

Why convert TOML to JSON?

JSON is universally supported by programming languages, APIs, and tools. Converting TOML to JSON is useful when you need to process configuration data programmatically, send it over an API, import it into a database, or use it with JavaScript/Node.js tools that expect JSON input.

How are TOML dates and times handled in JSON?

TOML has native date-time, local date, local time, and local date-time types. Since JSON has no dedicated date type, all TOML date and time values are converted to ISO 8601 formatted strings (e.g., "2024-01-15T10:30:00Z"). This is the universally accepted way to represent dates in JSON.

Are TOML comments preserved in the JSON output?

No. TOML supports comments using the # character, but JSON has no comment syntax. All comments in your TOML file are discarded during conversion. If the comments contain important information, consider preserving them in a separate documentation file or adding them as descriptive JSON keys.

What is the difference between TOML tables and inline tables?

In TOML, a standard table uses [table-name] header syntax with key-value pairs on separate lines, while an inline table uses curly braces on a single line like {key = "value"}. Both are semantically identical and both convert to the same JSON object structure. The distinction is purely stylistic in TOML.

Can I convert Cargo.toml files to JSON?

Yes. Cargo.toml files used by Rust projects are standard TOML files and can be converted to JSON without any issues. This is useful for processing Cargo metadata in CI/CD pipelines, building custom tooling, or analyzing dependency trees programmatically with tools that consume JSON.

Is my data secure during conversion?

Yes, all conversion happens directly in your browser using client-side JavaScript. Your TOML data is never sent to any server, stored in any database, or logged anywhere. This is especially important for configuration files that may contain sensitive values like API endpoints or internal hostnames.

How are TOML multi-line strings handled?

TOML supports multi-line basic strings (triple-quoted with """) and multi-line literal strings (triple-quoted with '''). Both are converted to standard JSON strings with newline characters represented as \n escape sequences. The content is fully preserved; only the representation changes.