TOML to JSON and JSON to TOML Converter
CV-18Paste TOML and press TOML to JSON to get JSON. If the TOML has a mistake, you get its message with the line and column. JSON to TOML converts the other way.
Runs in your browser. Nothing is uploaded.
TOML or JSON
Result
How to use it
- Paste your TOML into the input box, or open a file (up to 5 MB) or drop it on the box.
- Press TOML to JSON and choose 2 spaces, 4 spaces or Tab for the indent.
- If TOML has an error, read the message and fix the line and column it names.
- To go the other way, paste a JSON object and press JSON to TOML.
- Copy the result or download it as a file.
What TOML to JSON does
Tables become objects, arrays of tables become arrays of objects, and dotted keys are expanded. JSON has no date type, so every TOML date and time becomes a string, for example 1979-05-27T07:32:00.000Z for an offset date-time. Integers beyond 9007199254740991 are written exactly, with no rounding. A float such as 1.0 becomes 1, since JSON does not tell them apart. The TOML values inf and nan raise an error.
What JSON to TOML does
The top level of the JSON must be an object, because a TOML document is a table. Nested objects become tables and arrays of objects become arrays of tables. TOML has no null, so a null anywhere stops the conversion and the message gives its path. Big integers are written exactly, up to the 64-bit limit of TOML; a larger one gives an error. Strings stay strings, so an ISO date in JSON is not turned into a TOML date, and a whole number such as 1.0 is written as the integer 1.
Reading the errors
TOML errors come from the parser with the line and column where it stopped. Common causes are a key defined twice, a missing quote, two key-value pairs on one line, an invalid date, and an underscore in the wrong place in a number. Press Go to error to jump to that spot. Only the first error is shown, and the position can be on the line after the real mistake.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
invalid value at line 2, column 5 | A key was followed by something that is not a valid TOML value, or by nothing at all. | Write a string in quotes, a number, a boolean, a date, an array or an inline table after the equals sign. |
trying to redefine an already defined table or value at line 2, column 1 | The same key or table is defined twice, for example a.b = 1 and then a = 2. | Remove one of the definitions or give them different names. |
x is inf, which JSON cannot hold. Change it in the TOML first. | The TOML contains inf, -inf or nan, which JSON cannot write. | Replace the value with a number, a string or remove the key. |
A TOML document is a table, so the top level of the JSON must be an object { ... }. | The JSON is an array or a single value at the top level. | Wrap it in an object, for example { "items": [ ... ] }. |
TOML has no null value. Found null at a.b[1]. Remove the key or use a string. | The JSON contains null, which TOML cannot represent. The message gives the path. | Remove that key, or replace null with a string such as an empty one. |
Questions people ask
How do I convert TOML to JSON?
Paste the TOML and press TOML to JSON. Tables become objects and arrays of tables become arrays. Dates and times become strings. If the TOML is invalid you get the error with its line and column.
How do I convert JSON to TOML?
Paste a JSON object and press JSON to TOML. Nested objects become tables, and arrays of objects become arrays of tables. The top level must be an object, and null is not allowed because TOML has no null.
Why does JSON to TOML reject null?
TOML has no null value, so there is nothing to write. The error names the path of the null. Remove the key, or replace it with a string, depending on what your program expects.
What happens to dates in TOML to JSON?
They become strings, because JSON has no date type. An offset date-time such as 1979-05-27T07:32:00Z is written as 1979-05-27T07:32:00.000Z. A local date stays 2020-01-01, and a local time gets milliseconds, as in 07:32:00.000.
Does TOML to JSON keep large integers exact?
Yes. An integer such as 9223372036854775807 is written with all its digits. Be careful when you read that JSON in JavaScript, because JSON.parse there would round it. Use a parser that supports big integers.
Why did 1.0 become 1?
JSON has one number type and does not separate floats from integers, so the converter writes 1. Converting that JSON back to TOML gives the integer 1, not the float 1.0. Keep the TOML file as your source if the type matters.
About this tool
TOML to JSON turns every date and time into a string, because JSON has none, and writes integers beyond 9007199254740991 exactly. A float such as 1.0 becomes 1, since JSON does not tell them apart, so converting back gives an integer. TOML values inf and nan raise an error. JSON to TOML needs an object at the top and refuses null, which TOML cannot hold. Strings stay strings, so an ISO date in JSON is not turned into a TOML date.