TOML to JSON Converter

Convert TOML to JSON Online

Use our free toml to json data converter to transform TOML configuration files into structured JSON data instantly. Whether you are parsing Cargo.toml manifests for build tooling, extracting pyproject.toml settings for automation scripts, or migrating configuration data to JSON-based systems, this tool delivers accurate results without any software installation.

What is TOML Format

TOML, standing for Tom's Obvious Minimal Language, is a configuration file format created by Tom Preston-Werner that emphasizes human readability through clear, minimal syntax. TOML maps directly to a hash table structure, making it trivial to parse into native data structures in virtually any programming language. The format uses an equals sign for key-value assignment, square brackets for table headers, and double square brackets for arrays of tables.

TOML natively supports a rich set of data types including strings with both basic and literal variants, integers, floating-point numbers, booleans, offset datetime and local datetime values, arrays, and inline tables. Comments are supported using the hash symbol, and the format enforces UTF-8 encoding throughout. TOML has become the standard configuration format for the Rust ecosystem through Cargo.toml, the Python packaging ecosystem through pyproject.toml, and numerous Go applications. Its unambiguous specification ensures that every valid TOML document parses to exactly one data structure, eliminating the ambiguity issues found in some other configuration formats.

What is JSON Format

JSON, or JavaScript Object Notation, is a lightweight text-based data interchange format that has become the lingua franca of web APIs and modern application development. Originally derived from JavaScript object literal syntax, JSON is now fully language-independent with parsers and generators available in every mainstream programming language. Its simplicity and universality make it the default choice for data exchange between services, client-server communication, and structured data storage.

A JSON document consists of objects represented by curly braces containing key-value pairs, and arrays represented by square brackets containing ordered value sequences. JSON supports six value types: strings enclosed in double quotes, numbers without distinction between integers and floats, the boolean literals true and false, the null literal, nested objects, and nested arrays. While JSON lacks features like comments and explicit date types, its minimal specification ensures maximum interoperability across platforms and tools. JSON is the native format for REST APIs, MongoDB and other document databases, browser local storage, and countless configuration systems.

How the Conversion Works

Converting TOML to JSON involves parsing the section-based TOML structure and remapping it into the nested bracket-based format that JSON uses. The converter reads the TOML input, resolves all table headers and dotted keys into their fully nested hierarchy, and then serializes the resulting data structure as formatted JSON. TOML tables become JSON objects, TOML arrays become JSON arrays, and scalar values are mapped to their closest JSON equivalents.

Several important type mappings occur during conversion. TOML integers and floats are both represented as JSON numbers, though the distinction between them is lost. TOML datetime values are converted to ISO 8601 strings since JSON has no native date type. TOML comments are discarded entirely because JSON does not support comments. If you need to convert in the opposite direction, our JSON to TOML converter handles that transformation. You can also transform JSON into YAML for DevOps configuration workflows, or use our JSON to CSV converter when you need tabular output for spreadsheet analysis.

Syntax Comparison

Understanding the syntactic differences between TOML and JSON helps clarify the conversion process. A TOML configuration using table headers and bare keys looks like this:

# TOML
[server]
host = "localhost"
port = 8080
debug = true

The equivalent JSON representation uses nested braces and quoted keys:

// JSON
{
  "server": {
    "host": "localhost",
    "port": 8080,
    "debug": true
  }
}

TOML arrays of tables using double brackets like [[products]] become JSON arrays of objects. TOML dotted keys like database.connection.pool_size = 10 expand into deeply nested JSON objects. TOML inline tables like point = { x = 1, y = 2 } map directly to JSON objects. One notable difference is that TOML requires all keys within a table to be unique, while JSON technically allows duplicate keys though most parsers only keep the last value.

Common Use Cases

The most frequent reason to convert TOML to JSON is integrating configuration data with web applications and APIs that expect JSON input. Rust projects using Cargo.toml often need to extract dependency information or metadata into JSON for consumption by CI/CD pipelines, package registries, or dashboard applications that display project information.

Another common scenario involves Python projects that use pyproject.toml for build configuration. Build tools, linters, and automation scripts often need to read these settings programmatically, and converting to JSON makes the data accessible to any language or tool with a JSON parser. Data migration projects also benefit from this conversion when moving settings from TOML-configured applications to systems that store configuration in JSON format, such as VS Code settings, ESLint configurations, or cloud service definitions that require JSON input.

TOML to JSON Examples

The following examples demonstrate how various TOML structures are converted into their JSON equivalents using this data converter. These cover the most common patterns found in real-world configuration files.

A basic TOML table converts to a nested JSON object:

# TOML Input
[package]
name = "my-app"
version = "2.1.0"
edition = "2021"
authors = ["Alice", "Bob"]

// JSON Output
{
  "package": {
    "name": "my-app",
    "version": "2.1.0",
    "edition": "2021",
    "authors": ["Alice", "Bob"]
  }
}

Nested TOML tables with dotted keys expand into deeply nested JSON:

# TOML Input
[database]
host = "db.example.com"
port = 5432

[database.pool]
min_connections = 5
max_connections = 20
idle_timeout = 300

// JSON Output
{
  "database": {
    "host": "db.example.com",
    "port": 5432,
    "pool": {
      "min_connections": 5,
      "max_connections": 20,
      "idle_timeout": 300
    }
  }
}

TOML arrays of tables become JSON arrays of objects:

# TOML Input
[[dependencies]]
name = "serde"
version = "1.0"
features = ["derive"]

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

// JSON Output
{
  "dependencies": [
    {
      "name": "serde",
      "version": "1.0",
      "features": ["derive"]
    },
    {
      "name": "tokio",
      "version": "1.28",
      "features": ["full", "macros"]
    }
  ]
}

Frequently Asked Questions

Are TOML comments included in the JSON output?

No, TOML comments are discarded during conversion because JSON does not support comments of any kind. The JSON specification intentionally omits comments to keep the format simple and unambiguous. If you need to preserve documentation alongside your configuration data, consider storing comments as separate string values within the data structure itself, or maintain a companion documentation file alongside the generated JSON output.

How are TOML datetime values represented in JSON?

TOML supports four datetime types: offset datetime, local datetime, local date, and local time. Since JSON has no native date or time type, all TOML datetime values are converted to ISO 8601 formatted strings in the JSON output. For example, a TOML value of 2024-01-15T10:30:00Z becomes the JSON string "2024-01-15T10:30:00Z". Applications consuming the JSON output will need to parse these strings back into date objects using their language date parsing libraries.

What happens to the distinction between TOML integers and floats?

TOML explicitly distinguishes between integer values like 42 and float values like 42.0, but JSON has only a single number type. During conversion, both TOML integers and floats become JSON numbers. The converter preserves the numeric representation, so 42 remains 42 and 42.0 remains 42.0 in the output. However, some JSON parsers may normalize these values, potentially losing the original distinction. If the integer versus float distinction is critical, consider using string representations.

Can I convert the JSON output back to TOML?

Yes, our JSON to TOML converter can reverse the transformation. However, round-trip conversion may not produce identical TOML because comments are lost during the initial conversion, and TOML-specific formatting choices like inline tables versus standard tables cannot be inferred from JSON structure alone. For best results with round-trip workflows, keep your data structures straightforward and avoid relying on TOML-specific formatting.

Does the converter handle TOML inline tables?

Yes, TOML inline tables like point = { x = 1, y = 2 } are converted to standard JSON objects just like regular TOML tables. The distinction between inline tables and standard tables is purely a formatting choice in TOML and has no semantic difference. Both produce identical JSON object structures in the output. The converter treats them identically during the parsing and transformation process.

Is my data secure during conversion?

Absolutely. The entire TOML to JSON conversion is performed client-side in your browser. No data is transmitted to any external server at any point during the process. This makes the tool completely safe for converting sensitive configuration files that may contain database credentials, API keys, or other proprietary information. Your data remains entirely within your browser session and is never stored or logged.

How do TOML dotted keys translate to JSON?

TOML dotted keys provide a shorthand for defining nested structures. A key like server.database.host = "localhost" is equivalent to defining nested tables and translates to a deeply nested JSON object: {"server": {"database": {"host": "localhost"}}}. The converter fully expands all dotted keys into their nested object representation, producing clean and properly structured JSON output that accurately reflects the hierarchical relationships defined in the original TOML document.

FAQ

How does TOML to JSON Converter work?

Convert TOML data to JSON format online.

Ad