How to use it
Pick one of three options under “Mode”.
- Format: breaks the JSON onto separate lines and indents it so the structure is visible. Choose “2 spaces”, “4 spaces”, or “Tab” from the indent list.
- Minify: strips every space and line break between values and puts everything on one line. The indent list disappears in this mode.
- Validate: gives the same output as Format and adds a “This is valid JSON.” badge when the syntax is correct. If Format or Minify produced a result, that input has already passed the same syntax check.
The checkboxes apply in all three modes.
- Sort keys: sorts the keys of every object, nested ones included, by character code. Uppercase letters come before lowercase, and the letters A–Z and a–z come before non-ASCII characters such as
é,가, or日.{"z":1,"a":{"c":2,"b":3}}becomes{"a":{"b":3,"c":2},"z":1}. The order of items inside arrays is left alone. - Escape non-ASCII (\uXXXX): rewrites non-ASCII characters, such as accented letters and emoji, as
\uXXXXescapes."é😀"becomes"\u00e9\ud83d\ude00". An emoji is written as two escape codes. - Allow comments & trailing commas (JSON5/JSONC): covered in its own section below.
Three numbers appear under the result. “Keys” counts every key, including those in nested objects. “Depth” counts the outermost bracket as 1. “Size” is the UTF-8 byte count of the result, not of what you pasted. Format {"order":{"id":1001,"items":[{"sku":"A1","qty":2}],"paid":true}} with 2 spaces and you get Keys 6, Depth 4, Size 129B. Switch the same input to Minify and only Size goes down.
Same value, different spelling
The tool reads your input with the browser’s JSON parser (JSON.parse) and then writes it back out as text. So more than whitespace changes: wherever the input used one of several equivalent ways to write a value, the output settles on a single one.
| Input | Result |
|---|---|
1.0 |
1 |
0.10 |
0.1 |
1e2 |
100 |
1E-7 |
1e-7 |
-0 |
0 |
"\u00e9" |
"é" |
"a\/b" |
"a/b" |
The numeric values and string contents are the same, but the difference shows up if you compare the result with the original character by character, as in signature verification, hash comparison, or a line-based diff. -0 is the one case where something is lost: the sign disappears, so be careful if the data is headed for a program that tells negative zero apart from zero.
Three warnings for values that actually change
Sometimes a result comes out with no error, yet a value in it differs from the original. The tool flags three of those cases with a warning next to the result. The result is still shown when a warning appears.
- Integers longer than 15 digits: a JavaScript number holds integers exactly only up to 2^53 - 1 (9007199254740991). Paste
{"id":9007199254740993}and the result reads9007199254740992, with the last digit changed. The warning goes by digit count (integers of 16 digits or more), not by whether the value really changed, so it also appears for a 16-digit integer that survives intact, such as1234567890123456. Numbers with a decimal point or exponent and digits inside strings aren’t counted. If a large ID has to stay exact, whoever produces the data needs to emit it as a string ("id":"9007199254740993"). - Numbers outside the representable range: a number that’s too large, such as
1e400, turns intonullin the result. - Duplicate keys in the same object:
{"a":1,"a":2}becomes{"a":2}. The earlier value is dropped and only the last one remains. The warning lists up to five of the duplicated key names.
Reading the error position
When the syntax is wrong, you get a message such as “This isn’t valid JSON. Check around line 3, column 21.” in place of the result, along with the lines around the problem and a ^ marker.
2 | "name": "a",
3 | "tags": ["x", "y",]
| ^
4 | }
The ^ points at the first character the parser couldn’t get past. The cause is either there or just before it. In the example above the ^ sits under ], but the thing to fix is the comma in front of it. Only the first error is reported, so another one may show up after you fix this one.
These are the inputs that trip the parser most often.
- A comma after the last item:
[1, 2, 3,] - Single-quoted strings or unquoted keys:
{'a': 1},{a: 1} //and/* */comments- Numbers with a leading zero:
01 - Values JSON doesn’t have, such as
NaNandundefined - A raw line break inside a string (it has to be written as
\n)
Of these, only the comma and the comments can be waved through with the option below. The rest you have to fix by hand.
What the comments and trailing commas option does
Standard JSON (RFC 8259, ECMA-404) allows neither comments nor a comma after the last item (a trailing comma). Files that people edit by hand, such as editor settings files, often use JSONC (JSON with Comments) or JSON5 instead, which are variants that do allow them. With “Allow comments & trailing commas (JSON5/JSONC)” turned on, the tool removes // comments, /* */ comments, and any comma sitting right before a closing bracket, and only then parses the input. A // or a comma inside a string is not removed, so a value like "http://x//y" stays as it is.
Three things to know:
- Comments and commas are all it handles. Single quotes and unquoted keys, which JSON5 permits, are still errors with the option on.
- The result is standard JSON, so the comments are gone. You can’t use this to tidy the indentation of a file while keeping its comments.
- If an error occurs with the option on, the error snippet still shows your input as it was before comments were removed. The line and column numbers refer to your original too, so a
/* */comment that comes earlier on the same line than the error doesn’t throw the column number off.
If your goal is to confirm that data you received is standard JSON, leave this option off. With it on, input containing comments passes too.
