JSON5 to JSON Converter
CV-17Paste JSON5 and press JSON5 to JSON to get strict JSON. Comments, single quotes, unquoted keys, hex numbers and trailing commas are all accepted. JSON to JSON5 converts the other way.
Runs in your browser. Nothing is uploaded.
JSON5 or JSON
Result
How to use it
- Paste your JSON5 into the input box, or open a file (up to 5 MB) or drop it on the box.
- Press JSON5 to JSON. Pick 2 spaces, 4 spaces or Tab for the indent.
- To go the other way, paste JSON and press JSON to JSON5, then choose the quote style, unquoted keys and trailing commas.
- If a number would be rounded, read the message and tick Allow rounding of big numbers only if that is acceptable.
- Copy the result or download it as a file.
What JSON5 to JSON changes
JSON5 is a superset of JSON that allows comments, single-quoted and unquoted strings and keys, trailing commas, hex numbers such as 0xFF, a leading or trailing decimal point, a plus sign, and Infinity and NaN. The conversion writes strict JSON: comments are dropped because JSON has none, quotes become double quotes, hex becomes decimal and trailing commas disappear. Integer-like keys such as "2" move to the front of their object, which is how JavaScript orders them.
Numbers and what cannot be converted
The JSON5 side reads numbers as JavaScript numbers, which are exact only up to 9007199254740991. By default the tool stops with a message if a literal would be rounded, for example 12345678901234567890. Tick Allow rounding of big numbers to convert anyway. Infinity and NaN cannot be written in JSON, so they raise an error naming the key. Replace them with null or a string before converting.
JSON to JSON5
JSON to JSON5 keeps every number exactly as written. It leaves simple keys unquoted, such as name instead of "name", and quotes the rest, for example keys with spaces. You can choose single or double quotes, or let the tool pick the form that needs fewer escapes. Trailing commas are optional. Comments cannot be restored, because plain JSON never held any.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
invalid character '}' at line 2, column 5 | JSON5 found a character it cannot use at that position. Here a value was expected and a closing brace appeared. | Add the missing value, or remove the extra comma or brace at that position. |
invalid end of input at line 1, column 5 | The text ended while an object, array, string or comment was still open. | Close the bracket or quote that was left open. |
a is Infinity, which JSON cannot hold. Replace it with null or a string first. | The JSON5 holds Infinity, -Infinity or NaN. Strict JSON has no way to write these. | Replace the value with null or a string in the JSON5, then convert again. |
The number 12345678901234567890 at line 2, column 7 is too precise for a JavaScript number | A number has more digits than a JavaScript number can store, so converting would round it. | Write the value as a string, or tick Allow rounding of big numbers if the rounded value is fine. |
Questions people ask
How do I convert JSON5 to JSON?
Paste the JSON5 and press JSON5 to JSON. Comments are removed, quotes and keys are rewritten in strict JSON form, and trailing commas are dropped. Choose the indent you want, then copy the result.
Can I convert JSON with comments to JSON?
Yes, if the comments follow JSON5 style, with // for a line and /* */ for a block. They are dropped from the output. Other comment styles, such as lines starting with #, are not valid JSON5 and will raise an error.
Does JSON5 to JSON keep my comments?
No. JSON has no comment syntax, so the comments are removed. If you need them, keep the JSON5 file as the source and treat the JSON as generated output.
Why does it refuse to convert a big number?
JSON5 is read with JavaScript numbers, and 12345678901234567890 cannot be stored exactly. Converting would silently change it to 12345678901234567000. The tool stops instead, unless you tick Allow rounding of big numbers.
How do I convert JSON to JSON5?
Paste the JSON and press JSON to JSON5. Simple keys lose their quotes, strings use your chosen quote style, and numbers are copied exactly. Add trailing commas if your style guide wants them.
Why did my keys change order?
Keys that look like whole numbers, such as "1" or "2", are moved to the front of their object, in numeric order. That is how JavaScript orders object keys. Other keys keep the order you wrote.
About this tool
JSON5 to JSON drops comments, since JSON has none, and writes hex numbers, leading or trailing decimal points and single-quoted strings in plain JSON form. It reads numbers as JavaScript numbers, so by default it refuses a number that would be rounded; tick the box to convert anyway. Integer-like keys such as "2" are moved to the front of their object, which is how JavaScript orders them. Infinity and NaN cannot be written in JSON, so they raise an error. JSON to JSON5 keeps number text exactly and cannot restore comments.