What parsing and formatting really do
Formatting is not a text operation. The input is parsed into JavaScript values and then serialised again, and that round trip explains almost every surprise on this page.
1. Parse first, format second
The Format button does not add line breaks to your text. It calls JSON.parse on the trimmed input, then JSON.stringify with an indent of two spaces. Minify calls the same parser and stringifies without an indent. Validate parses the input and shows the formatted result, so a successful format and a successful validate are the same syntax check.
value = JSON.parse(text) formatted = JSON.stringify(value, null, 2) minified = JSON.stringify(value)
Because the output is rebuilt rather than edited, it can differ from the input even when the JSON is valid: whitespace is normalised, number spellings are shortened, and some members disappear. The data model survives; the original byte layout does not.
2. Indentation is always two spaces
The formatter uses a fixed indent of two spaces. Tabs, four spaces and aligned colons are not offered, because the tool passes the number 2 as the third argument to JSON.stringify. Every nesting level adds exactly two spaces, and arrays put one element per line.
If your team uses four spaces, the formatted output is still a correct preview of the structure, but it will not match the repository style. Copy the result into your editor and run its own formatter before committing, so the diff contains only real changes.
Minify removes all insignificant whitespace, including the line breaks and spaces inside the pretty version. It does not shorten keys, numbers or strings, so the saving is layout only.
3. Key order is preserved, with one exception
JSON.parse creates properties in the order they appear in the source, and JSON.stringify walks them in the same order. That is why a formatted document usually looks like the input. The exception is keys that look like array indexes.
- Keys such as 0, 1, 2 or 10 are enumerated first, in ascending numeric order.
- All other keys follow in insertion order, after the numeric ones.
- Nested objects follow the same rule at every level.
An object written as 2, 10, 1, name comes back as 1, 2, 10, name. This is a JavaScript property-order rule, not a bug in the formatter, and it can matter when two systems compare serialised strings byte for byte. Compare parsed values, not raw text.
Do not rely on key order for meaning. If order matters, use an array of objects with an explicit position field.
4. Duplicate keys: the last one wins, silently
JSON allows a member name to appear more than once, and the parser keeps only the last occurrence. The formatter cannot show you the conflict, because the earlier value is already gone by the time the output is built. A document with three copies of the same key formats cleanly and reports no error.
{"a":1,"a":2} → {"a":2}
The tool reports syntax errors, not data-quality problems. Detecting duplicate keys requires a parser that records every member, not JSON.parse.
5. Numbers pass through IEEE 754 doubles
JSON has one number type and it is mapped to a double-precision float. Integers stay exact only up to 2^53 − 1, which is 9,007,199,254,740,991. Beyond that the stored value is the nearest representable double, and formatting prints that rounded value.
largest exact integer = 2^53 − 1 = 9007199254740991
| Literal in the input | Value after parse | Output after format |
|---|---|---|
| 9007199254740991 | 9007199254740991 | 9007199254740991 |
| 9007199254740993 | 9007199254740992 | 9007199254740992 |
| 12345678901234567890 | 12345678901234567000 | 12345678901234567000 |
| 1.0 | 1 | 1 |
| 1e2 | 100 | 100 |
| -0 | -0 | 0 |
| 1e400 | Infinity | null |
The last row is worth remembering. A number larger than the double range parses as Infinity, and serialising Infinity produces null, so an overflowing value is replaced rather than flagged. An ID of 20 digits loses its tail for the same reason: a customer identifier ending in 7890 can come back ending in 7000.
JSON.parse accepts 1e400 because it is syntactically a number; it never warns that the value overflowed. Validate ranges separately from syntax.
6. Large integers belong in strings
Snowflake IDs, database bigints, order numbers and phone numbers should be quoted in JSON. A quoted value is a string, so every digit survives the round trip, and the receiving system can parse it with its own 64-bit integer type.
{"id":"12345678901234567890"} keeps all 20 digits
This is a contract decision, not a formatting trick. Changing a number to a string can break strict schema validation, so agree the type with the API owner first.
7. What is not JSON
- Trailing commas after the last member or array element.
- Single quotes around strings or member names.
- Comments, whether written with two slashes or slash-star.
- Unquoted keys, as in JavaScript object literals.
- undefined, NaN and Infinity used as literals.
- Hexadecimal numbers such as 0x1F, and numbers with a leading zero.
- A byte-order mark before the opening brace.
The tool trims spaces, tabs and line breaks at both ends before parsing, so ordinary indentation is fine. It does not strip a BOM, and the BOM is not JSON whitespace, so a file saved by some Windows editors fails on the very first character.
8. Where the error message comes from
The message after Parse failed is the browser's own JSON.parse exception. Chrome, Edge, Firefox and Safari word it differently and report different positions, so treat the text as a hint about the kind of mistake, not as a stable API.
| Input | Typical message | Cause |
|---|---|---|
| {"a":1,} | Unexpected token } or Expected double-quoted property name | trailing comma after the last member |
| {'a':1} | Unexpected token ' | single quotes instead of double quotes |
| {a:1} | Unexpected token a | key not wrapped in double quotes |
| [1,2,] | Unexpected token ] | trailing comma inside an array |
| {"a":NaN} | Unexpected token N | NaN is not a JSON value |
| {"a":1} {"b":2} | Unexpected non-whitespace character after JSON | two documents pasted together |
| a line break inside a string | Bad control character in string literal | raw newline instead of the two-character escape |
An empty box shows the tool's own message, Please enter JSON content, without calling the parser at all. Whitespace-only input behaves the same way because the input is trimmed first.
9. Escapes, Unicode and line breaks
Inside a string, a backslash introduces an escape. Backslash-n becomes a newline, backslash-t a tab, and backslash-u followed by four hex digits becomes one UTF-16 code unit. Quotes and backslashes themselves must be escaped, otherwise the string ends early and the rest of the document is read as garbage.
Formatting does not escape non-ASCII text. Chinese, Japanese and emoji stay readable in the output, because JSON.stringify only escapes quotes, backslashes and control characters. A file that arrived full of backslash-u sequences therefore comes back with real characters, which is shorter and easier to read but no longer byte-identical.
The formatted output is still valid JSON and still UTF-8. If a downstream system requires pure ASCII, run a separate ASCII-escaping step after formatting.
10. Nothing leaves the browser
Parsing, formatting, minifying and copying all happen in the page. No request carries your document to a server, so internal configuration, tokens and customer records are not uploaded. The same applies to the base64 and URL encoding tools on this site, which run in the same tab.
Local processing removes network exposure, not the risk of pasting secrets into a shared screen. Close the tab after working with production data.