JSON Formatter and Validator

Drop a JSON file here

or paste below — .json, .txt, .geojson, .jsonl (one document)

Options

Paste JSON or drop a file and get it back indented, sorted or minified. Errors are explained in plain words with the line and column, duplicate keys are listed instead of silently dropped, and numbers too large for JavaScript keep every digit in the output. It runs in your browser, so a file with customer data or API keys is never uploaded.

How to format and check JSON

  1. Paste your JSON into the box, or drop a .json file on the page.
  2. Read the line under the box. If the text is valid it says so and counts the objects, arrays and keys; if not, it names the problem and points at the character.
  3. Pick a layout — two spaces, four spaces, tabs or minified — and tick Sort keys if you want every object in alphabetical order.
  4. Copy the result or download it as formatted.json.

A formatter should not change your data

The shortest way to write a JSON formatter is to parse the text and print it back. It is also the way that quietly changes things, because parsing turns every number into a JavaScript double. Give it this array and see what comes back:

[12345678901234567890, 9007199254740993, 1.0, 1E5, 1e999]

→ [12345678901234567000,9007199254740992,1,100000,null]

That second line is what JSON.stringify(JSON.parse(text)) returns in Chrome, checked here rather than assumed. The first two numbers lost their last digits, the next two changed the way they are written, and the last became null. An order number, a database id or a 19-digit timestamp in nanoseconds does not survive that. How often it happens depends on the kind of ID: we ran 470,000 simulated ones through JSON.parse and wrote up which ones change and which do not.

This page reads the text into its own tree that keeps each number and string exactly as written, and prints those. The output above stays as you typed it. Numbers that a JavaScript program could not hold exactly are listed with what JavaScript would turn them into, so you find out before a script does it for you.

Duplicate keys disappear without a warning

{"a":1,"a":2} is legal JSON. The standard only says keys should be unique, and most parsers then keep the last one: JSON.parse returns a as 2 and the 1 is gone. Merged config files and hand-edited exports produce duplicates all the time, and a formatter built on JSON.parse repairs them by deleting data.

Here each duplicate is listed with its path and both line numbers — $.b.c (lines 2 and 3) — and stays in the output so you choose which to keep. Two spellings of the same key, "a" and "a", are the same key to a parser, and the report says so.

Errors that say what is wrong

The parser is written to explain, not just to refuse. The message names the usual causes: a trailing comma, single quotes, an unquoted key, a comment, a missing comma between two items, NaN or undefined, a number with a leading zero, a raw line break inside a string, an object that is never closed. The line and column are given, a pointer sits under the exact character, and Go to the error selects it in the box. If another document begins where the first ended, it says the text looks like JSON Lines — one document per line — which is a different format from a single JSON file.

How it was checked

The result was compared with Python's json module rather than with itself. Sixty randomly generated documents, containing accents, Chinese characters, emoji, escapes and integers past 264, were formatted in all four layouts and matched json.dumps character for character, and sorted output matched sort_keys. A further 73 tricky inputs — [01], [1.], {"a":1,}, ["\x"], [NaN], a raw tab in a string and the like — were accepted or rejected exactly as Python accepts or rejects them. A 7 MB document with 60,000 records was parsed and formatted in about 0.7 seconds and came out identical to Python's output.

Comments and trailing commas

Standard JSON has neither. Files such as tsconfig.json and VS Code settings do, and they are read by tools that accept a looser dialect often called JSONC. Tick Accept comments and trailing commas to read those; the page counts what it removed, because the formatted result is strict JSON and the comments are not carried over. With the box unticked they are errors, which is what a strict parser such as JSON.parse will say.

Turning JSON into a spreadsheet? JSON to CSV collects columns from every record, and JSON to XML reports names that collide. Working with times inside the data? The Unix timestamp converter reads whole columns of them. Nothing you paste is uploaded.

Frequently asked questions

How do I format JSON online?

Paste it into the box or drop a .json file on the page. The formatted result appears below straight away, indented with two spaces by default. Switch the layout to four spaces, tabs or minified, and tick the sort option to put every object's keys in order. Then copy the result or download it as formatted.json.

Why does my JSON say it is invalid?

The message names the cause and the position. The usual ones are a trailing comma after the last item, single quotes instead of double quotes, a key without quotes, a comment, a missing comma between two items, and a value such as NaN or undefined that JSON does not have. The pointer under the offending line shows the exact character, and Go to the error selects it in the box.

Does formatting change my numbers?

Not here. Many formatters parse the text into JavaScript values and print them again, which turns 12345678901234567890 into 12345678901234567000 and 1.0 into 1. This page keeps the original text of every number and string, so the output has exactly the digits you put in. It also tells you which numbers a JavaScript program could not hold exactly.

What happens with duplicate keys?

JSON does not forbid them, but every common parser keeps only the last value, so the earlier ones vanish without a warning. This page lists each duplicate with its path and both line numbers and leaves all of them in the output, so you can decide which to keep. Two keys that are written differently but mean the same, such as "a" and "a", are caught as well.

Can it handle comments and trailing commas?

Only if you ask it to. Standard JSON allows neither, so by default they are reported as errors. Tick Accept comments and trailing commas to read files such as tsconfig.json or VS Code settings; the formatted result is strict JSON, so the comments are not carried over.

Is there a size limit?

No fixed one. Everything runs in your browser, so the limit is your device's memory; a document of about ten megabytes formats in well under a second on a laptop. Nesting deeper than 2,000 levels is refused with a message rather than crashing the page.

Is my JSON uploaded anywhere?

No. The parsing and formatting are plain JavaScript on this page. That matters for API responses and config files that contain tokens, addresses or customer records.