JSON Formatter
Published Updated
Paste JSON to check it as you type, then indent it with two spaces or minify it onto one line.
Formatting re-parses your JSON
Format and Minify both run JSON.parse and then JSON.stringify. That checks the whole document and produces clean output, but it also means the tool rewrites values rather than only changing whitespace. For almost all JSON the data comes back identical. The exceptions are worth knowing before you paste a payment ID or a database export.
Values that change when you format
Results from this page's formatter in Google Chrome 157, Chromium 153 (Playwright build, not Google Chrome), Firefox 155 and Playwright's WebKit build (not the Safari app). All four gave the same output on every row:
| You paste | You get | Why |
|---|---|---|
| 12345678901234567890 | 12345678901234567000 | Beyond 2^53 a number loses precision |
| 1.0 | 1 | A number keeps no trailing zeros |
| 1e3 | 1000 | Exponents are written out |
| -0 | 0 | Negative zero is written as 0 |
| "caf\u00e9" | "café" | Escapes become the characters they stand for |
| {"a": 1, "a": 2} | {"a": 2} | Duplicate keys: the last one wins |
| 9007199254740993 | 9007199254740992 | The nearest number a 64-bit float can hold |
| 1e400 | null | Too large for a 64-bit float, so it becomes Infinity, which JSON writes as null |
| 1e20 and 1e21 | 100000000000000000000 and 1e+21 | From 1e21 up, numbers keep an exponent |
| {"b": 1, "10": 3, "2": 4} | {"2": 4, "10": 3, "b": 1} | Keys that are whole numbers move to the front, in numeric order |
The JSON standard, RFC 8259, notes that integers between -(2^53)+1 and 2^53-1 are the ones all implementations agree on exactly, and that object names should be unique.
Common errors and what they mean
The message under the box is the browser's own JSON.parse error, so it depends on the browser. The same inputs in three of them:
| Input | Chrome 157 and Chromium 153 | Firefox 155 | WebKit build |
|---|---|---|---|
{"a": 1,} (trailing comma) | Expected double-quoted property name in JSON at position 8 (line 1 column 9) | JSON.parse: expected double-quoted property name at line 1 column 9 of the JSON data | JSON Parse error: Property name must be a string literal |
[1, 2,] (trailing comma) | Unexpected token ']', "[1, 2,]" is not valid JSON | JSON.parse: unexpected character at line 1 column 7 of the JSON data | JSON Parse error: Unexpected comma at the end of array expression |
{'a': 1} (single quotes) | Expected property name or '}' in JSON at position 1 (line 1 column 2) | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data | JSON Parse error: Single quotes (') are not allowed in JSON |
{"a": 1} // note (comment) | Unexpected non-whitespace character after JSON at position 9 (line 1 column 10) | JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 10 of the JSON data | JSON Parse error: Unrecognized token '/' |
{"a": True, "b": None} (Python values) | Unexpected token 'T', "{"a": True, "b":"... is not valid JSON | JSON.parse: unexpected character at line 1 column 7 of the JSON data | JSON Parse error: Unexpected identifier "True" |
{"a": 1 "b": 2} (missing comma) | Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9) | JSON.parse: expected ',' or '}' after property value in object at line 1 column 9 of the JSON data | JSON Parse error: Expected '}' |
| A line break typed inside a string | Bad control character in string literal in JSON at position 12 (line 1 column 13) | JSON.parse: bad control character in string literal at line 1 column 13 of the JSON data | JSON Parse error: Unterminated string |
{"a": 01} (leading zero) | Unexpected number in JSON at position 7 (line 1 column 8) | JSON.parse: expected ',' or '}' after property value in object at line 1 column 8 of the JSON data | JSON Parse error: Expected '}' |
Chrome 157 and Firefox 155 give a line and column counted from 1, and the Chrome 157 message adds a position counted from 0. The WebKit build names the problem without a place, so in a long file search for the character it names. When Format or Minify fails, the box keeps your text exactly as it was.
How big the output gets, and how deep Format can go
Generated test documents, pasted with a four-space indent. The byte counts are the same in all four browsers:
| Generated document | Pasted | After Format | After Minify |
|---|---|---|---|
| 1,000 product records with 11 fields each | 325,227 bytes | 249,227 bytes | 146,226 bytes |
| One array of 10,000 numbers | 127,823 bytes | 107,823 bytes (10,002 lines) | 77,822 bytes |
| A tree 8 levels deep with two branches per level | 163,853 bytes | 91,109 bytes | 14,535 bytes |
| A 200 by 50 grid of numbers as nested arrays | 128,074 bytes | 87,274 bytes (10,402 lines) | 36,073 bytes |
Format puts every array value on its own line, so the 10,000 numbers take 10,002 lines. Depth costs the most: the 8-level tree is about 6 times its minified size after Format, and 1,000 nested empty arrays take 2,000 bytes minified and 2,000,000 bytes formatted.
Valid JSON appeared for 1,000,000 nested arrays in every browser. Format and Minify then walk the data recursively, and that has a limit, measured with this page's formatter by narrowing down to the last depth that worked:
| Nesting | Chrome 157 | Chromium 153 | Firefox 155 | WebKit build |
|---|---|---|---|---|
| Deepest nested arrays Format handled | 4,726 | 5,117 | 3,792 | 6,000 (the deepest tried) |
| Deepest nested objects Format handled | 5,120 | 5,117 | 4,198 | 6,000 (the deepest tried) |
| Message one level deeper | Maximum call stack size exceeded | Maximum call stack size exceeded | too much recursion | No error up to 6,000 levels |
| Minify on 1,000,000 levels | Works | Works | too much recursion (already at 5,000 levels) | Maximum call stack size exceeded. (worked at 20,000, failed at 50,000) |
Formatting JSON
Step 1
Paste your JSON
It is checked on every change. A green Valid JSON label or the parser's error message appears under the box.
Step 2
Format or minify
Format / Prettify rewrites it with two-space indentation. Minify removes every optional space and line break.
Step 3
Copy the result
Copy to Clipboard copies the box as it is now, formatted or not.
Converting instead of formatting
- To a spreadsheet: JSON to Excel or JSON to CSV.
- To YAML or XML: JSON to YAML, JSON to XML.
- Escaping JSON to put inside a string: JSON Escape / Unescape.
JSON formatter questions
Why does formatting change my numbers?
The JSON is parsed into JavaScript values and written out again, and JavaScript numbers are 64-bit floating point. Integers beyond 9,007,199,254,740,991 lose precision: 12345678901234567890 comes back as 12345678901234567000. Keep IDs like that as strings. Also, 1.0 becomes 1 and 1e3 becomes 1000.
Where is the error in my JSON?
The message under the box comes from the browser's own parser and usually names a position. In Chrome a trailing comma reads like Expected double-quoted property name in JSON at position 8 (line 1 column 9). Count from the first character, starting at 0.
Does it accept comments or trailing commas?
No. Standard JSON allows neither, and neither single quotes, unquoted keys or NaN. Files such as tsconfig.json often contain comments, so they show as invalid here even though their own tools read them.
What happens to duplicate keys?
The last one wins and the earlier ones disappear when you format. With {"a": 1, "a": 2} you get {"a": 2}. The JSON standard says names should be unique and warns that parsers handle duplicates differently.
Can it sort keys or change the indent?
No. The indent is always two spaces, and Minify is the only other output. Keys keep their order with one exception: keys that are whole numbers come first, in numeric order, so {"b": 1, "10": 3, "2": 4} is written as {"2": 4, "10": 3, "b": 1}. JavaScript objects order such keys that way.
Is my JSON uploaded?
No. The JSON is processed in your browser by JavaScript in this tab; this page does not upload it.
Why did a very large number turn into null?
A number such as 1e400 is valid JSON, but it is too large for the 64-bit numbers JavaScript uses, so it is read as Infinity, and JSON has no way to write Infinity. Format and Minify both turned [1e400, -1e400] into [null, null] in all four browsers, while the label still said Valid JSON. Store such values as strings.
Why does Format fail on JSON the page calls valid?
Very deep nesting. The check that shows Valid JSON passed 1,000,000 nested arrays, but Format stopped at 4,727 nested arrays in Chrome 157 and at 3,793 in Firefox 155 with a stack error. In Chrome 157, Minify still worked at 1,000,000 levels.
How much smaller does Minify make a file?
It depends on the shape. For 1,000 generated product records, Format gave 249,227 bytes and Minify 146,226, 41% less. A tree 8 levels deep shrank from 91,109 to 14,535 bytes, because most of its formatted size was indentation.
Can I paste JSON that starts with a byte order mark?
No. An invisible U+FEFF at the start was refused in all three browsers tested: Chrome 157 reports an unexpected token, Firefox 155 an unexpected character at line 1 column 1, and the WebKit build an unrecognized token. RFC 8259 says parsers "MAY ignore the presence of a byte order mark", and these browsers do not. Delete the first character, or save the file as UTF-8 without BOM.