What parsing and formatting really do

Last updated 2026-11-29

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.

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 inputValue after parseOutput after format
900719925474099190071992547409919007199254740991
900719925474099390071992547409929007199254740992
123456789012345678901234567890123456700012345678901234567000
1.011
1e2100100
-0-00
1e400Infinitynull

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

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.

InputTypical messageCause
{"a":1,}Unexpected token } or Expected double-quoted property nametrailing comma after the last member
{'a':1}Unexpected token 'single quotes instead of double quotes
{a:1}Unexpected token akey not wrapped in double quotes
[1,2,]Unexpected token ]trailing comma inside an array
{"a":NaN}Unexpected token NNaN is not a JSON value
{"a":1} {"b":2}Unexpected non-whitespace character after JSONtwo documents pasted together
a line break inside a stringBad control character in string literalraw 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.

Open the JSON Formatter

Keep reading