JSON formatter and validator
How to format and check JSON
- Paste your JSON into the first box. The page checks it a moment after you stop typing.
- If an error message appears, read the line and column it gives and the few characters it quotes. Fix that spot and the message updates.
- Choose Format to indent the text or Minify to put it on one line. For Format, pick 2 spaces, 4 spaces or Tab.
- Tick Sort keys A to Z if you want the keys of every object in alphabetical order. Lists keep their order.
- Press Copy result, or Download .json to save a file named formatted.json.
How the JSON formatter reads your text
The page does not use your browser's JSON.parse. It has its own parser that follows the JSON standard (RFC 8259) strictly and reads the text one character at a time. The error message therefore comes from the page, not from the browser, and should not change from one browser to the next. We only tested Chromium 158, so we cannot say how other browsers behave.
Strict means no comments, no single quotes, no trailing commas, no unquoted keys, no NaN or undefined, and no leading zeros or plus signs on numbers. A byte order mark at the start of the text is ignored. Empty input and input made only of spaces do nothing and show no message.
The parser builds a tree of what you typed instead of turning numbers into JavaScript values. That is why numbers keep their digits and repeated keys survive.
Reading an error message
Every error comes with a line and a column, both counted from 1. A tab counts as one column and an emoji counts as two, because the page counts UTF-16 code units.
For a bad number, a bad backslash or a string that never closes, the column points at the start of the problem. Chromium's own message for the same text often points a few characters later. In our 24 invalid inputs, Chromium gave a line and column for 16. For 10 of those 16 it matched the page. For the other 6 it was later, by 1 to 14 columns.
- Trailing comma. For an object whose third line ends in
[1, 2, 3,], the page says: Line 3, column 17: JSON does not allow a comma before a closing bracket or brace. Remove the last comma. Chromium's message for the array gave no position at all. For a trailing comma in an object it gave position 16, line 1 column 17. - String that never closes. For
{"a": "never closed}the page names where the string starts (line 1, column 7). Chromium said line 1, column 21, where the text ended. - Bad backslash. A Windows path such as
"C:\Users\ana"gives line 1, column 13, the backslash itself. Chromium said column 14. - Others with their own message. A bad number such as
007,5.or0x1Fis reported at its first digit. A raw line break or tab inside a string, text after the value has ended (two objects pasted one after the other) and brackets left open each have a message too.
Everything else gets one general message: Not valid JSON at line L, column C, near the quoted text, with a hint to check for a missing quote, comma, colon or bracket. In our runs that covered single quotes, a comment, an unquoted key, a missing comma, a missing colon, a plus sign, NaN, True and undefined. The page does not name the mistake in those cases. Where Chromium gave a position for one of them, it was the same line and column.
What the formatter keeps and what it changes
We ran one line through Minify and through JSON.stringify(JSON.parse(text)), which is what many scripts do. The line held a 20-digit integer, 9007199254740993, 1.0, 1E5, -0, 0.10, a number with 34 decimals, a string "007" and the key a twice. Minify returned the text unchanged. Run through the script, seven of the numbers changed: 12345678901234567890 became 12345678901234567000, 9007199254740993 became 9007199254740992, 1.0 became 1, 1E5 became 100000, -0 became 0, 0.10 became 0.1 and the long decimal became 0.1. It also dropped the first a.
JavaScript numbers are exact only up to 9007199254740991. Long ids, amounts with trailing zeros and very precise decimals are safe here.
The page does change string escapes. \u00e9 comes out as é, \ud83d\ude42 as 🙂, \/ as / and \u0041 as A. \n stays \n. The meaning is the same but the text is not identical to what you pasted. White space between tokens always changes, which is the point of the tool.
Format, minify and sort
We ran the two JSON samples in the test set through every option. nested.json (444 bytes, 18 keys, 4 levels) came out at 443 bytes with 2 spaces, 571 with 4 spaces, 379 with a tab and 267 minified. A short list of three objects (192 bytes) gave 191, 251, 161 and 105. Minified text was about 40 and 45 percent smaller than the 2-space version. A tab is one byte per level. In every run without sorting, parsing the output gave the same data as parsing the input.
Sort keys A to Z compares keys by character code, not by dictionary order. Digits come first, then capital letters, then lowercase letters, then accented ones. We sorted b, B, a, A, é, z, 10, 9, a1 and got 10, 9, A, B, a, a1, b, z, é. The text 10 sorts before 9 because they are compared as text. Sorting reaches every level of nesting. It does not reorder lists, but objects inside a list are sorted. If a key appears twice, the two stay in the order you typed them.
Large files
The page sets no size limit and takes pasted text only. We generated lists of 1,000, 10,000, 40,000 and 100,000 objects and timed the paste in Minify mode until the result appeared. The 15 MB list took 6.0 seconds. The parser alone, running Format with 2 spaces, needed 0.8 seconds for the same text, so most of the wait is not parsing. We did not measure where the rest goes. Sorting added about a quarter on the largest list (1.0 seconds against 0.8). Times varied from run to run. The table below has the figures.
Format adds bytes: the 15 MB list became 24.8 MB with 2 spaces.
The usual mistakes and how to fix them
JSON looks like a JavaScript object, and most errors come from the differences.
- Trailing comma. Delete the comma after the last item.
- Single quotes and unquoted keys. Use double quotes. For
{'name': 'Ana'}the page points at line 1, column 2. - Comments. JSON has none. Remove the
//lines, or keep the file in an editor that reads JSON with comments. - Values from code.
Truemust betrue.NaNandundefinedhave no JSON form, so usenullor a string. - Backslashes in paths. Write each one twice:
"C:\\Users\\ana". - Line breaks in a string. Write
\ninstead of pressing Enter inside the quotes. - Several objects, one per line. That is JSON Lines, not JSON. Paste one line at a time.
The page does not repair anything. It shows the first problem, and you fix it by hand.
Things the page does that can surprise you
These came up in testing. We did not change them.
- Nesting of 2,001 levels worked. At 2,002 levels, and at 100,000, the page showed the general message (line 1, column 2002) and an empty result. The message does not mention depth.
- "Levels deep" in the status line counts levels that hold something.
[]is 0 levels,[[]]is 1 and[[1]]is 2. - "Keys" counts every key at every depth, repeated keys included. The bytes figure is the size of the result, not of your input.
- Download adds a newline at the end. A 443-byte result was saved as a 444-byte file, with no byte order mark.
What stays in the browser
We opened the page with outside connections blocked, pasted an object that held a unique marker string, formatted it, minified it with sorting and copied the result. The page made 12 requests, all for its own files except two outside scripts, the Google ad script and the Google tag. Both were blocked in the test, so we cannot say what they would send. None of the requests carried a body and none had the marker in its address. localStorage and sessionStorage held no keys. Nothing in the page's own code sent your text anywhere.
Next steps for your JSON
To move data into another format, use the JSON to CSV, CSV to JSON, YAML and JSON converter or XML and JSON converter. The JSON to CSV page reports broken JSON in the browser's own words, which do not always include a position, so check the text here first.
Measured results
| Test | What we ran | What came out |
|---|---|---|
| nested.json, 444 bytes | Format with 2 spaces, 4 spaces, Tab, then Minify | 443, 571, 379 and 267 bytes; 18 keys, 4 levels |
| array-of-objects.json, 192 bytes | The same four options | 191, 251, 161 and 105 bytes |
| invalid.json, 54 bytes | Format | Line 3, column 17 (trailing comma), result empty, Copy and Download disabled |
| 24 inputs that are not valid | One for each kind of mistake (two are empty), next to Chromium's JSON.parse | 22 gave a line and column (empty and blank input gave none); Chromium gave one for 16, matching 10 of them |
| One line of 10 members | Minify, against JSON.parse and JSON.stringify | Page: text unchanged. Script: 7 numbers changed and a repeated key lost |
| Deep nesting | 2,001, 2,002 and 100,000 levels | 2,001 worked; the other two were refused with the general message |
| 1,000 objects, 145,430 bytes | Paste, Minify | 156 ms to result; parser 14 ms (Format, 2 spaces) |
| 10,000 objects, 1.5 MB | Paste, Minify | 539 ms; parser 88 ms |
| 40,000 objects, 6.1 MB | Paste, Minify | 2.6 seconds; parser 437 ms |
| 100,000 objects, 15.3 MB | Paste, Minify | 6.0 seconds; parser 801 ms, with sorting 994 ms |
| Copy and download | Format nested.json, then both buttons | Copy matched the box; formatted.json, 444 bytes against 443, parses back |
| Network test | Paste a marker, format, minify, copy | 12 requests, 2 outside (ad script, Google tag), 0 bodies, 0 naming the marker, storage empty |
Prefer desktop software?
A code editor suits a file you keep editing. It can colour the text, fold sections and read JSON with comments, such as VS Code settings or a tsconfig file, which this page rejects. For many files or a script, a command-line tool can run the same job in bulk. VS Code formats JSON with Shift+Alt+F, and Python has python -m json.tool. We did not test any desktop editor or command-line tool.
Frequently asked questions
Is my JSON uploaded?
No. In our test the page's own code made no request that carried your text, and browser storage stayed empty. The ad script and the Google tag run on the page, and we blocked both in the test, so we cannot say what they would send.
Why does my JSON fail here when my program accepts it?
Programs often read looser text than JSON allows: single quotes, unquoted keys, comments and trailing commas all work in a JavaScript object. This page follows the JSON standard, so it reports each of them. The section on usual mistakes lists the fixes.
Will formatting change my numbers?
No. In our test a 20-digit integer, 1.0, 1E5, -0 and 0.10 came out exactly as typed. A script that uses JSON.parse changed all of them. String escapes such as \u00e9 are the one thing the page rewrites, to é.
What happens to a key that appears twice?
Both are kept, in the order typed, and both count in the status line. Sorting keeps them in that order too. A script that uses JSON.parse keeps only the last one.
Can it fix my JSON for me?
No. It reports the first problem with its line and column, and you fix it by hand. Once that is fixed, a second error further down may appear.
How large can the JSON be?
The page sets no limit. We tested up to 15.3 MB, which took 6.0 seconds from paste to result in Minify mode. Bigger text depends on your browser and memory, and we did not test it.
Can I open a file instead of pasting?
Not on this page. There is no file picker or drag and drop. Open the file in a text editor, copy all of it and paste it here. The Download .json button saves the result.
Why is the column different in my editor?
The page counts columns from 1 in UTF-16 code units, so a tab is one and an emoji is two. An editor may count differently. Use the quoted text to find the spot.