JSON Formatter
Tidy up messy JSON, minify it for sending, or find the line with the mistake. Your data never leaves the browser.
Paste JSON, then press Format. Shortcut: Ctrl or Cmd + Enter.
How to use it
- Paste JSON into the input box, or press Open file to pick a .json file.
- Press Format to indent it, or Minify to remove spaces and line breaks.
- If there is an error, you see the line, the column and the cause. Press Jump to error to go straight to it.
The rules of JSON
JSON is defined by RFC 8259 (December 2017). It has only seven kinds of value: object {}, array [], string, number, true, false and null, and those three words must be lowercase. Any value can stand at the top level, so "hello" or 42 on its own is valid JSON.
- Strings use double quotes. The quotation mark, the backslash and the control characters U+0000 to U+001F (line breaks included) must be escaped, for example as
\",\\,\nor\u00e9. - Numbers are decimal, with no leading zeros and no plus sign.
0.5and1e-3are valid;.5,1.,007,0x1F,NaNandInfinityare not. - Whitespace means space, tab, line feed and carriage return only, around
{ } [ ] : ,. - Names within an object should be unique. If they repeat, the RFC says the behavior of the receiving software is unpredictable. A browser's
JSON.parsekeeps the last value; this tool keeps both when formatting.
JSON exchanged between systems that are not part of a closed ecosystem must be UTF-8, and a byte order mark must not be added. This tool removes a BOM if it finds one.
The most common mistakes
- Trailing comma:
[1, 2,]→[1, 2] - Single quotes:
{'a': 'b'}→{"a": "b"} - Unquoted name:
{a: 1}→{"a": 1} - Python values:
True,None→true,null - JavaScript value:
undefined→null - Windows path:
"C:\data"→"C:\\data" - Comment:
// note→ removed
The tool runs its own character-by-character check, so it can name the cause instead of only a position. For {"a": 1 "b": 2} it reports Line 1, column 9: A comma is missing between two values. A Python True gets Write true in lowercase.
JSON is not a JavaScript object
JSON looks like a JavaScript object literal but is much stricter. JavaScript accepts unquoted names, single quotes, trailing commas, comments, undefined, functions and hexadecimal numbers; JSON accepts none of them. The other way round, since ES2019 every valid JSON text is also a valid JavaScript expression, after the language started allowing the characters U+2028 and U+2029 inside string literals.
Large numbers and key order
Format and Minify change only whitespace. In {"id":12345678901234567890,"price":25000.50}, both numbers stay exactly as written. A round trip through JSON.parse would turn the ID into 12345678901234567000 and the price into 25000.5, because JavaScript numbers are exact only up to 253 − 1. Sorting keys uses character code order: capitals come before lowercase letters, and é comes after z.
Questions
Is my JSON sent to a server?
Do large numbers and special characters change?
\u00e9 stay exactly as written. A formatter that goes through JSON.parse turns 12345678901234567890 into 12345678901234567000.What are the most common mistakes?
undefined or True. None of these are allowed in standard JSON.How do I write a Windows path or a line break inside a string?
"C:\\data". Write a line break as \n instead of pressing Enter inside the quotes. Otherwise the tool reports an invalid escape or a line break inside a string.