Result

Paste some JSON above to begin.

Everything runs in your browser. Nothing you paste here is sent anywhere.

How it works

JSON is a text format, and whitespace outside of strings carries no meaning in it. Beautifying or minifying a document does not change the data at all — only how it is broken across lines. So you can minify freely before sending and beautify again to read, and lose nothing either way.

The genuinely useful part of this page is the error. When `JSON.parse` fails, the browser throws something like `Unexpected token o, ..."b": oops\n}" is not valid JSON` — with no line number anywhere in it. In a 400-line document that message is close to useless. This page works out the real character offset and turns it into a line and a column.

How it does that depends on the message. Some errors carry `at position N` and the conversion is arithmetic. The `Unexpected token` family — the common one — gives only a snippet around the failure, so this page locates that snippet in your document and then checks the character it lands on against the one the message named. If they disagree it reports no position rather than guessing: a wrong line number is worse than none.

Sorting keys alphabetically helps when comparing two versions of the same document: two files with identical content but different key order produce a diff that is entirely red. Array order is left alone, because in an array the order is data.

Formula

JSON.stringify(value, null, spaces)

The second argument is a replacer function, null here because nothing is filtered. A third argument of 0 produces the minified string — which is why "indent 0" and "minify" give the same result.

Worked example

A document missing the quotes around a value:

Line 1
{
Line 2
"a": 1,
Line 3
"b": oops
The browser says
Unexpected token 'o' …
This page says
Error on line 3, column 8

The same failure, but one message makes you search the document and the other points straight at the fix.

Frequently asked questions

Does beautifying change my data?

No. Whitespace outside strings is meaningless in JSON, so the beautified and minified forms are two spellings of the same data. Whitespace inside a string is preserved.

Why is my JSON invalid when it looks fine?

The three usual causes: a trailing comma before a closing bracket, single quotes instead of double, and comments. JSON allows none of them, even though JavaScript does.

How much does minifying save?

Typically 15–30% on an indented document, depending on how deeply nested it is. The figure for your document is shown under the result.

Why does an error sometimes show no line number?

Because for some error shapes the browser does not give enough information to locate the failure with confidence. Rather than print a number that might be wrong, this page prints none.

Does sorting keys break anything?

No. Key order in a JSON object is not significant by the specification, so a reordered object is the same data. Array order is significant and is left untouched.

Is what I paste sent to a server?

No. Parsing and formatting run entirely in your browser, so you can paste internal data here without it leaving your machine.

Sources

Report a problemWrong result, out-of-date figures or a display bug? Send it from here. The page address and tool name are attached for you — just describe what is wrong.

Report a problem

The more specific the faster it gets fixed: what you entered, what you got, and what you expected.

What kind of problem?
0/2000

Only used to reply to you, nothing else.

Sent with your report

Page
/en/json-formatter
Tool
JSON Formatter
Language
English

The values you typed into the tool are not sent. Besides what is listed below, the server records the browser type and uses your IP address to rate-limit submissions — the privacy policy has the detail.