Data & Formats

TOML ⇄ JSON Converter

Convert TOML to JSON in your browser: paste a Cargo.toml, pyproject.toml or any TOML file and get clean JSON. A strict parser reports mistakes with the line, column and a fix. It also turns JSON back into TOML.

Ready.

What this tool does

It reads TOML, the configuration format behind Rust's Cargo.toml, Python's pyproject.toml, Hugo and many other tools, and writes the same data as JSON for scripts, APIs and other tools. The parser is strict: a file that is not valid TOML is rejected with the exact line and column instead of being half-converted. The reverse direction, JSON to TOML, is built in too.

  • Errors you can act on. Each error shows the line, the column, the offending line with a caret, and a short “how to fix” note.
  • Exact integers. TOML integers are 64-bit. Values past JavaScript's safe range keep every digit in the JSON text instead of being silently rounded.
  • Type-aware output. Choose whether floats such as 3.0 stay floats, and whether inf and nan raise an error or become strings.
  • TOML 1.0 or 1.1. 1.0 is the default and the most widely supported. Switch to 1.1 for newlines inside inline tables, optional seconds in times, and the \e and \xHH escapes.
  • Private by design. Conversion happens in your browser. Large files are handled in a background worker so the page stays responsive.

How to use it

  1. Paste TOML into the input box, or press Example to load a small Cargo-style manifest.
  2. Pick the JSON indent and, if you need them, the TOML version, float and inf/nan options. The result updates as you type.
  3. Read the notes under the output. They tell you when something could not map one-to-one, for example dates written as strings.
  4. Copy or download the JSON, or use Send JSON to to open it directly in the JSON Formatter, JSON Validator, JSON to Code or another JSON tool. To check a file without converting it, paste it into the TOML Validator.

TOML to JSON conversion explained

TOML and JSON describe the same kind of data, nested objects, arrays and scalar values, so most of the mapping is direct. TOML adds typed dates, comments and several string forms; JSON has none of those, so a few things change on the way.

TOMLJSON result
Table [server], dotted keys a.b = 1Nested object: {"server": {...}}, {"a": {"b": 1}}
Inline table { min = 2, max = 10 }The same nested object
Array [1, 2, 3]JSON array. TOML 1.0 allows mixed types in one array.
Array of tables [[servers]]Array of objects, one per [[servers]] header
Basic, literal and multi-line stringsOne JSON string with escapes resolved (\n, \u00e9 and so on)
Integers (decimal, 0x, 0o, 0b, underscores)JSON number written in decimal, digits kept exact up to 64-bit
Floats, inf, nanJSON number; inf and nan have no JSON form (see options)
Booleanstrue / false
Date and time valuesRFC 3339 strings (see the section on dates)
Comments, key order inside the file, blank linesNot carried over; JSON has no comments

Nested tables and dotted keys

A header such as [server.tls] creates tls inside server, and url.host = "db.internal" creates the same kind of nesting from a dotted key. Parent tables you never write out are created implicitly.

title = "Service config"

[server]
host = "0.0.0.0"
port = 8080

[server.tls]
enabled = true
cert = "/etc/ssl/app.pem"

[database]
url.host = "db.internal"
url.port = 5432
pool = { min = 2, max = 10 }

becomes

{
  "title": "Service config",
  "server": {
    "host": "0.0.0.0",
    "port": 8080,
    "tls": {
      "enabled": true,
      "cert": "/etc/ssl/app.pem"
    }
  },
  "database": {
    "url": {
      "host": "db.internal",
      "port": 5432
    },
    "pool": {
      "min": 2,
      "max": 10
    }
  }
}

Arrays and arrays of tables

Square brackets with a single pair, [server], define one table. Double brackets, [[servers]], define one more item in a list of tables every time they appear. A sub-table written after an item, such as [servers.limits], belongs to the most recent item, not to the whole list. That last rule is the one people most often get wrong when reading TOML by eye, so the output below is worth a look.

ports = [8000, 8001]
mixed = [1, "two", true]

[[servers]]
name = "alpha"
ip = "10.0.0.1"

[[servers]]
name = "beta"
ip = "10.0.0.2"

[servers.limits]
cpu = 2

becomes

{
  "ports": [
    8000,
    8001
  ],
  "mixed": [
    1,
    "two",
    true
  ],
  "servers": [
    {
      "name": "alpha",
      "ip": "10.0.0.1"
    },
    {
      "name": "beta",
      "ip": "10.0.0.2",
      "limits": {
        "cpu": 2
      }
    }
  ]
}

Dates, times and number types

JSON has no date type, so every TOML date or time is written as a string, exactly as RFC 3339 spells it. The converter does not shift time zones or guess a zone for local values, because that would change the meaning of your data.

odt = 1979-05-27T07:32:00Z
offset = 1979-05-27T00:32:00-07:00
ldt = 1979-05-27T07:32:00
ld = 1979-05-27
lt = 07:32:00

becomes

{
  "odt": "1979-05-27T07:32:00Z",
  "offset": "1979-05-27T00:32:00-07:00",
  "ldt": "1979-05-27T07:32:00",
  "ld": "1979-05-27",
  "lt": "07:32:00"
}
TOML typeHas an offset?Example
Offset date-timeYes (Z or +05:00)1979-05-27T07:32:00Z
Local date-timeNo1979-05-27T07:32:00
Local dateNo1979-05-27
Local timeNo07:32:00

Numbers need the same care. TOML separates integers from floats, while JSON has one number type. With Keep float notation on, a float with no fractional part stays 3.0 in the JSON text; with it off it is written as 3. Integers outside JavaScript's safe range (more than 9,007,199,254,740,991) are written with every digit:

count = 42
mask = 0xFF
ratio = 3.0
avogadro = 6.02e23
big = 9223372036854775807

with float notation on becomes

{
  "count": 42,
  "mask": 255,
  "ratio": 3.0,
  "avogadro": 6.02e+23,
  "big": 9223372036854775807
}

Be aware that JSON.parse in JavaScript will round that last value. If your consumer is JavaScript, read it with a BigInt-aware parser or keep such values as strings in the TOML itself.

TOML vs JSON

The two formats overlap, but they are built for different readers. TOML is meant to be written and edited by people; JSON is meant to be produced and consumed by programs.

TOMLJSON
CommentsYes, with #No
Dates and timesFour native typesNone; strings by convention
Integers and floatsDistinct typesOne number type
NullNot availablenull
Top levelAlways a table of keysAny value
Trailing commasAllowed in arraysNever
Multi-line textTriple-quoted stringsNeeds \n escapes
Typical homeConfig files you editData exchanged between programs

A common workflow is to keep configuration in TOML for readability and convert to JSON when a tool needs it. If you are moving between several formats, the YAML ⇄ JSON Converter and YAML ⇄ JSON Converter cover the other popular configuration format, and the .env ⇄ JSON Converter handles environment files.

Common TOML errors and how to fix them

These are messages this converter really produces. Each points at a line and column, and the output box stays empty until the document is valid. One mistake does not produce an error at all: in path = "C:\temp" the \t is a valid escape for a tab, so the value silently contains a tab character. Prefer single quotes for Windows paths and regular expressions.

MessageTypical causeFix
Duplicate key "a"The same key twice in one table: a = 1 then a = 2.Remove one, or collect the values in an array.
The table "t" is already definedTwo [t] headers. Keys added later under a second header are rejected.Merge the keys under the first header. Use [[t]] if you want a list.
Expected a valueAn unquoted string such as name = demo, or True instead of true.Quote text: name = "demo". Booleans are lowercase.
Expected a valid number: leading zeros are not allowedport = 08080 or a zero-padded number.Write 8080, or quote the value if the zeros matter.
Invalid unicode escapeA Windows path in double quotes: "C:\Users\me". Backslash starts an escape, and \U expects eight hex digits.Use single quotes for the literal string 'C:\Users\me', or double the backslashes.
Expected ',' or ']' in an arrayA missing comma or a missing closing bracket.Separate items with commas and close with ].
Newlines and comments are not allowed inside an inline table in TOML 1.0An inline table { ... } spread over several lines.Keep it on one line, use a [table] section, or switch the TOML version to 1.1.
Invalid dateA date that does not exist, such as 2024-02-30.Use a real calendar date in YYYY-MM-DD form.
Integer is outside the 64-bit range TOML allowsAn integer larger than 9223372036854775807 or smaller than -9223372036854775808.Store it as a string.
Expected the end of the line but found 'y'Two pairs on one line: x = 1 y = 2.Put each key = value pair on its own line.

When you only want to know whether a file is valid, without looking at the JSON, the TOML Validator runs the same parser and reports the same positions; the two tools are meant to be used together, validating first and converting once the file is clean.

Important conversion limitations

  • Comments and formatting are lost. JSON cannot hold them, so converting TOML to JSON and back does not reproduce the original file.
  • Dates become strings. After a round trip they are ordinary quoted strings in TOML, not date values.
  • JSON null cannot become TOML. TOML has no null, so JSON to TOML reports the problem instead of dropping the key. The top level must be an object.
  • Big integers and JavaScript. The JSON text is exact, but any JavaScript code that parses it will round numbers beyond 9,007,199,254,740,991.
  • Key order. JSON objects are unordered by definition. Keys that look like whole numbers ("1", "2") are listed first in ascending order, as JavaScript objects always do, so they may not appear where they did in the TOML file.
  • Syntax only. The tool checks that the file is valid TOML. It does not know whether the keys make sense for Cargo, pip or Hugo.
  • Size. Input up to 8 MiB is accepted. Documents over about 100,000 characters are converted in a background worker.

Developer use cases

  • Read a manifest from a script. Convert pyproject.toml or Cargo.toml to JSON, then pull a field out with jq or the JSONPath Tester.
  • Compare two versions of a config. Convert both and compare them in the JSON Diff tool. Comments and key order stop creating noise, and only real value changes remain.
  • Check a config against a schema. Send the JSON to the JSON Schema Validator to confirm required fields and types.
  • Generate types. Turn a settings file into TypeScript, Go or Python models with JSON to Code.
  • Clean up or shrink the result. Reformat it in the JSON Formatter, or compress it with the JSON Minifier before embedding it.
  • Move to another config format. Convert on to YAML with the YAML ⇄ JSON Converter when migrating tooling.

Privacy and local processing

This tool runs entirely in your browser. What you paste or open is processed on your device and is not sent to a server, and there is no account or upload. Large documents are converted in a background worker loaded from this site, which also runs locally. If you use Send JSON to, the text is held briefly in this browser tab's session storage so the next tool can read it, then removed.

Share this tool

Your data is not included in this link.