TOML to JSON Converter
Parse TOML configurations and translate them into standard JSON documents.
A quick bridge for simple configuration
TOML favors human-edited configuration, while JSON is the native interchange shape for browsers, JavaScript services, and many APIs. This TOML to JSON converter is useful when a small settings block must become a test fixture, package metadata needs quick inspection, or a JSON-only consumer cannot read a straightforward TOML table. Paste input on the left; two-space-indented JSON appears on the right and can be copied.
The implementation is intentionally lightweight. It reads lines and recognizes a practical subset rather than implementing the complete TOML 1.0 grammar. That makes it suitable for simple flat tables, but not a replacement for a standards-compliant parser in a build or deployment pipeline.
What the line parser recognizes
A trimmed line enclosed by [ and ] starts a root-level section. A line containing = becomes an assignment in the current section. Double-quoted strings lose their outer quotes, bracketed comma-separated values become arrays, lowercase true and false become booleans, and numeric-looking values become JavaScript numbers. Text after # in a value is removed.
environment = "staging"
workers = 4
debug = false
[service]
hosts = ["api-1", "api-2"]
timeout = 2.5
The converted structure is:
{
"environment": "staging",
"workers": 4,
"debug": false,
"service": {
"hosts": ["api-1", "api-2"],
"timeout": 2.5
}
}
Assignments before any header stay on the root object. After a header, assignments remain in that section until another header appears. Blank lines and lines without an equals sign have no effect. Comments do not appear in JSON because JSON has no standard comment syntax.
From manifest excerpt to fixture
For a Cargo.toml workflow, isolate a basic [package] block or flat [dependencies] section. Paste that excerpt, inspect every converted value, then copy it into a temporary test fixture or analysis script. Reducing the source first is important: production Cargo manifests often include dotted keys, inline tables, target-specific sections, and feature maps outside this converter’s subset.
A similar technique works with a small pyproject.toml extract. Convert one uncomplicated table, compare the property names and primitive types with the receiving JSON schema, and only then save the result. The online TOML to JSON converter is best used as an exploratory bridge, not as an unattended compiler.
Tables do not become arbitrary trees
Every section name becomes one property directly on the JSON root. [database] creates database. A dotted header such as [servers.production] becomes the literal key servers.production; it does not construct nested servers and production objects. Repeating a section replaces the earlier object, so earlier assignments in that section are lost.
Arrays of tables such as [[products]] are not modeled as JSON arrays. Quoted keys, dotted assignments, inline tables, nested tables, and multiline values likewise need a full TOML parser. If exact semantic equivalence matters, use the TOML library maintained for your language and validate its JSON output in automated tests.
Value conversion details
The assignment is split on =. Only the first value segment is used, so a quoted URL or token containing an equals sign can be truncated. The comment handling also removes content after # without understanding quoted-string context. For example, a color string "#336699" will not survive correctly. Literal single-quoted strings and TOML’s multiline string forms are not decoded.
Array handling removes brackets, splits on commas, trims items, and removes double quotes. It does not recursively parse item types. Consequently, [1, 2, true] yields string members rather than JSON numbers and a boolean. A comma inside an array string also splits the item. Empty arrays can produce an empty-string member rather than a genuinely empty JSON array.
Numeric values use JavaScript number conversion. Ordinary integers and decimals work, but TOML dates and times remain strings, and special TOML numeric forms should not be assumed safe. Very large integers can lose precision because JSON serialization is fed JavaScript numbers. Preserve exact identifiers as nonnumeric text and verify boundary values.
A careful conversion checklist
- Reduce the input to uncomplicated scalar assignments and single-bracket sections.
- Remove or rewrite values containing
#,=, multiline syntax, inline objects, or commas inside array strings. - Paste the text and read the output rather than treating appearance as proof.
- Check section names, arrays, booleans, numbers, and leading-zero identifiers.
- Copy only after comparing against the consumer’s expected JSON schema.
- Run a real TOML parser when source fidelity or automation is required.
The output pane updates immediately. If the input is empty, both output and error are cleared. The copy button is disabled when no successful output exists.
TOML and JSON do not preserve the same information
Even a complete conversion is not textually reversible. TOML comments, ordering intent, whitespace, quoting style, and formatting disappear. TOML date-time types have no native JSON equivalent and require a representation policy. JSON also permits a root array, whereas typical TOML documents model a root table. Conversion should therefore be viewed as mapping data, not translating punctuation.
This distinction matters in configuration review. A resulting JSON object may be useful to an application while being unsuitable as a replacement source file. Keep the original TOML under version control and treat generated JSON as an artifact when the TOML remains authoritative.
Checking the result with a schema
Once the JSON is copied, parse it again in the destination language and validate expected properties explicitly. A JSON Schema can assert that workers is an integer, debug is boolean, and service.hosts is an array of strings. Schema validation catches a different class of problem from TOML parsing: the conversion may be syntactically successful while producing the wrong shape or type.
For a migration, create representative fixtures containing zero, negative and decimal numbers, empty text, hashes, equals signs, and arrays. Compare the tool result with output from a conforming TOML parser. Any difference identifies input that should leave the lightweight workflow. This small differential test is more dependable than judging indentation or quoted values by sight.
Separate conversion success from parser coverage
The output is produced after ordinary JavaScript object construction and JSON.stringify, so the JSON serializer usually succeeds even when the TOML reader skipped or truncated source meaning. The error panel is therefore not a coverage report. Before using copied output, compare the count of expected assignments with the resulting properties and inspect every source line containing more than one equals sign or a hash inside quotes. Those are direct stress points for the component’s split operations. Also confirm that selecting a repeated table did not discard earlier entries when a new empty section object replaced the old one.
Diagnosing unexpected output
If a value stops at an equals sign, the line contains more than one =. If text after a hash disappears, the simple comment removal interpreted it as a comment. If [a.b] appears as the JSON property a.b, that is the root-level section behavior. If array numbers are quoted, that reflects nonrecursive array parsing rather than JSON formatting.
When a repeated section loses earlier keys, consolidate it before conversion. If a malformed line silently disappears, check that it includes = and is on one line. The component rarely raises syntax errors because it does not perform full TOML validation; plausible output can still be incomplete. Review is therefore more valuable than relying on an error message.
Appropriate and inappropriate uses
Good uses include a small hand-written configuration example, documentation sample, quick API mock, or one-off examination of basic metadata. Poor uses include converting a complete lockfile, deploying secrets, migrating a complex manifest, or generating production configuration automatically. For sensitive values, remember that transformation is local to the page, but clipboard managers, browser extensions, and screen sharing remain part of the operating environment.
Common questions
Does it support nested TOML tables?
Only simple named sections become root-level JSON objects. Dotted and nested table semantics are not expanded.
Why are values in my array strings?
Array items are split and cleaned as text. Scalar type inference is applied to standalone assignments, not recursively to array members.
Can it convert an entire pyproject.toml?
Simple excerpts may work, but modern project files commonly use constructs beyond this parser. Use a conforming library for complete files.
Is the displayed result valid JSON?
Yes, output is produced by JSON.stringify. Valid JSON does not guarantee that all TOML meaning was captured.
Are comments preserved?
No. Trailing hash content is removed, and JSON offers no standard comment field.
Why did a large integer change?
The converter uses JavaScript numbers, which cannot exactly represent every integer beyond the safe range. Keep precision-sensitive values as strings or use a specialized conversion pipeline.