Skip to content

{ } · 2 / 4 / tab · minify

JSON formatter and validator

A JSON formatter adds indentation to compact JSON: a 60-byte document grows to 86 bytes with 2 spaces and to 102 bytes with 4. Paste JSON to get formatted or minified text, or the line and column of the first error.

Everything runs in this tab and nothing is uploaded. The parser follows RFC 8259, so comments, single quotes, trailing commas and unquoted keys are reported as errors.

Scanned by NortonTM Safe Web

At a glance

Price
No charge
Account
None needed
Standard
RFC 8259 (JSON)
Limits
5 MB of input, 512 levels of nesting
Output
2 spaces, 4 spaces, tab or minified, keys optionally sorted
Upload
None — the text stays in your browser tab

JSON errors and number precision

These figures come from the parser this page uses. Lines and columns count from 1.

First error found in a broken document
DocumentReason codeLine:column
{"a": 1,}trailing_comma1:8
{'a': 1}single_quotes1:2
[1, 2unexpected_end1:6
{"a": 01}bad_number1:8
{"a": "x\q"}bad_escape1:9
{"a": 1 "b": 2}missing_comma1:9
Numbers that JSON.parse rounds
Number as writtenValue JSON.parse returns
1234567890123456789012345678901234567000
90071992547409939007199254740992
1.00000000000000011
1E400Infinity

How to format JSON

1

Paste your JSON

Type or paste a JSON document of up to 5 MB into the input box. A sample is already there so you can see the result first.

2

Choose the output

Pick 2 spaces, 4 spaces, a tab or the minified form. Tick the box to sort the keys of every object in code-unit order.

3

Copy it or fix it

Copy or download the result. If the JSON is broken, the message gives the line, the column and the reason, and a caret marks the spot in the failing line.

How the JSON formatter works

The page reads your text with its own parser for the JSON grammar in RFC 8259, then writes it back with the indentation you chose. Because the parser is part of the page, every browser shows the same message for the same mistake. The built-in JSON.parse words its errors differently in Chrome, Firefox and Safari, and not all of them point to a line and column.

Numbers and string escapes are copied exactly as you typed them. JSON.parse turns 12345678901234567890 into 12345678901234567000, because a JavaScript number is a 64-bit float with about 15 to 17 significant digits. This page keeps all 20 digits and tells you when a number would be rounded. RFC 8259 says object names should be unique, so duplicate keys are kept and reported. The limits are 5 MB of input and 512 levels of nesting.

JSON formatter questions

How do I format JSON online?

Paste the JSON into the input box. The formatted text appears at once, with 2 spaces, 4 spaces or a tab for each level. The 60-byte sample becomes 86 bytes with 2 spaces and 102 bytes with 4 spaces.

What does "unexpected token" mean, and where is my error?

It means the parser met a character that the JSON grammar does not allow at that point. This page names the reason, the line and the column. For {"a": 1,} it reports trailing_comma at line 1, column 8.

Why is a trailing comma an error in JSON?

The grammar in RFC 8259 requires a value after every comma, so [1, 2,] and {"a": 1,} are invalid. JavaScript object literals accept a trailing comma, but JSON does not. Delete the last comma.

Can JSON contain comments or single quotes?

No. RFC 8259 has no comments, and strings and keys use double quotes only. Formats such as JSON5 and JSONC allow both, but they are different formats, and this page reports them as errors.

Does the formatter change my numbers?

No. Numbers and escapes are written back exactly as typed. JSON.parse would round 12345678901234567890 to 12345678901234567000, but this page keeps every digit, so formatting loses nothing.

Is my JSON uploaded anywhere?

No. The page runs in your browser tab and sends nothing to any server. Once it has loaded it also works offline. The input limit is 5 MB.