JSON Formatter
Format and indent JSON with 2 spaces, 4 spaces or tabs, and download the result.
Everything is processed in your browser. Nothing you paste is uploaded or stored.
In-depth guide
JSON formatting: what Format, Minify and Validate really do
How the formatter parses with the browser's JSON.parse, which values survive the round trip, what changes (key order, big numbers, duplicate keys) and how to read its error messages.
Key figures at a glance
- Parser
- The browser's built-in JSON.parse, strict RFC 8259 syntax
- No comments, no trailing commas, no single quotes, no NaN.
- Source: IETF — RFC 8259
- Indentation choices
- 2 spaces, 4 spaces or a tab
- Minify uses no whitespace at all.
- Numbers
- Parsed as IEEE 754 double precision
- Integers above 9007199254740991 and decimals needing more than about 17 significant digits can change.
- Download
- formatted.json
- The file contains whatever is in the output box, formatted or minified.
How the three buttons work
The page parses your text with JSON.parse and, if that succeeds, writes the value back with JSON.stringify. Nothing is sent anywhere; the work happens in the browser.
- Format writes the value with the chosen indent: 2 spaces, 4 spaces or a tab character.
- Minify writes it with no whitespace between tokens.
- Validate only parses and reports "Valid JSON" or the error; the output box is left alone.
Leading and trailing whitespace is trimmed first. Empty input shows "Please enter JSON data". The status banner disappears after three seconds, and editing the input clears the output so a stale result never sits next to new text.
Because the output is a re-serialisation, not a text edit, the result is "the same data written canonically", not "your text with spaces changed". That matters in the cases below.
What can change in the round trip
| You paste | Output | Why |
|---|---|---|
{"b":1,"2":"x","1":"y"} |
keys "1", "2", then "b" |
JavaScript lists integer-like keys first, in ascending order |
{"a":1,"a":2} |
{"a":2} |
The last duplicate wins; RFC 8259 says duplicates make behaviour unpredictable |
12345678901234567890 |
12345678901234567000 |
Double precision keeps about 15–17 significant digits |
9007199254740993 |
9007199254740992 |
Above 2^53 − 1 not every integer is representable |
1.50, 1.0, 5E+2 |
1.5, 1, 500 |
Numbers are re-printed, not preserved as text |
-0 |
0 |
JSON.stringify writes negative zero as 0 |
1e400 |
null |
Overflows to Infinity, which JSON.stringify writes as null |
"é" |
"é" |
Escapes are decoded, then characters are written literally where legal |
These were produced by running the same JSON.parse/JSON.stringify calls the page uses. The safe rule: formatting is lossless for strings, booleans, null, arrays and ordinary numbers; it is not lossless for very large IDs, duplicate keys, or numeric-looking keys whose order you care about. If a 19-digit ID must survive, keep it as a string in the source.
Format, minify and size
For the object {"name":"Mei","tags":["a","b"],"n":{"x":1,"y":[]},"e":{}} (57 characters minified), the 2-space version is 102 characters, 4 spaces is 130 and a tab is 88. Empty arrays and objects stay on one line as [] and {}. A top-level value can be any JSON value: 5, "text", [] are all valid under RFC 8259, although older parsers only accepted an object or array at the top.
Reading error messages
When the engine's message contains position N, the tool converts it to "Error at line L, column C" and then appends the engine's own text. Messages come from your browser, so wording differs between Chrome, Firefox and Safari, and some messages carry no position at all (for example [NaN] reports only that token N is unexpected). Typical causes:
| Input | Problem |
|---|---|
{"a":1,} |
Trailing comma: expected a double-quoted property name |
{'a':1} |
Single quotes are not JSON |
[1,2 |
Missing closing bracket |
{"a":01} |
Leading zeros are not allowed |
{"a":"x⏎y"} |
A raw line break inside a string; write \n |
// note or /* */ |
Comments are not part of JSON |
[NaN], Infinity, undefined |
Not JSON values |
Tip: Fix the first reported position and re-run. One missing quote often produces many follow-on errors, but only the first is real.
Common mistakes
- Pasting JavaScript object literals (unquoted keys, single quotes) and expecting them to validate.
- Assuming the formatter keeps the original key order: numeric-looking keys move to the front.
- Minifying a document with huge numeric IDs and then comparing it digit by digit with the source.
- Treating the download as the original file; it is the re-serialised output, always named
formatted.json.
Related tools
Check syntax only with the JSON validator, shrink with the JSON minifier, explore nested data with the JSON viewer, turn rows into tables with JSON to CSV, or compare two versions with the text diff.
Frequently asked questions
How do I format JSON with 4 spaces or tabs?
Use the Indentation menu above the editor to choose 2 spaces, 4 spaces or tabs. The output updates at once, and Download saves it as formatted.json.
Is my JSON sent to a server?
No. Everything happens in your browser. Nothing you paste is uploaded, logged or stored, which matters when the document contains keys, tokens or personal data.
Why is my JSON reported as invalid?
The most common causes are trailing commas, single quotes instead of double quotes around keys and strings, and unescaped line breaks inside a string. The error message gives the line and column of the first problem.
Does it change my data?
No. The document is parsed and re-serialised, so only whitespace changes. Key order is preserved and values are untouched.
Can it handle large documents?
Yes, within your browser's memory. Documents of a few megabytes are fine; extremely large files may make the page pause briefly while it parses.
Sources
- IETF — RFC 8259, The JSON Data Interchange Format — Grammar, number interoperability, duplicate names and member order.
- MDN — JSON.stringify() — Indent argument, Infinity and NaN written as null.
- ECMAScript language specification — Own-property ordering (integer-like keys first) used when objects are re-serialised.
This guide explains published rules in plain language. It is not financial, legal or official advice — rules change, so confirm with the agency linked above before you commit.
Related tools
Embed this tool on your website
Free to use. Paste this code into your page and keep the link back to ToolSG.