Developer tools

JSON formatter, validator and repair

Paste JSON to pretty-print it, minify it or sort its keys. If it does not parse, you get the exact line and column of the first error and the most likely reason. If it is the almost-JSON that ChatGPT, Claude and other models often produce, click Repair to get valid JSON and a list of what was changed.

Runs entirely in your browser. Nothing you enter here is uploaded.

How to format or validate JSON

  1. Paste your JSON into the Input JSON box. It can be a single line from a log, a whole API response or a configuration file.
  2. Choose the indentation — two spaces, four spaces or tabs — and whether keys should be sorted alphabetically.
  3. Press Format (or Ctrl+Enter, ⌘+Enter on a Mac). The result appears on the right, with a summary of how many keys the document has, how deeply it is nested and its size in bytes.
  4. Press Minify instead to remove all whitespace, for example before pasting JSON into an environment variable or a URL parameter.
  5. If the input is not valid JSON, a red box tells you the line and column of the first problem and what usually causes it. Show in input jumps to that spot.
  6. If the text is almost-JSON from an AI model — wrapped in a code block or an explanation, with single quotes or comments — click Repair. The result shows the repaired, formatted JSON with a list of every kind of change; your input is left as it was.
  7. Copy the result or download it as a .json file.

Inputs over one megabyte are formatted in a background thread so the page stays responsive. Nothing you paste leaves the page.

How the formatter works

JSON is defined by RFC 8259 and ECMA-404. It allows exactly six kinds of value: objects, arrays, strings in double quotes, numbers, true/false and null. Everything else people are used to from JavaScript — comments, single quotes, trailing commas, unquoted keys, NaN, undefined — is invalid, and every strict parser rejects it.

Why it does not use JSON.parse

The obvious way to build a JSON formatter is to call the browser's JSON.parse and then JSON.stringify. That quietly changes your data. JavaScript numbers are 64-bit floating point, so any integer larger than 2^53 (9,007,199,254,740,992) loses precision: 12345678901234567890 comes back as 12345678901234567000. Database IDs, Twitter/X status IDs and many financial amounts are exactly that size. JSON.parse also rewrites 1.0 as 1 and 1e3 as 1000.

This tool uses its own small parser instead. It reads numbers as text and writes them back exactly as they appeared, so the formatted output contains the same values as the input, character for character. Strings are decoded and re-encoded, which normalises escapes such as \u00e9 into the character é; the value itself is unchanged.

How errors are located

The parser reads the text from left to right and stops at the first character that cannot appear there. Its position is converted to a line and column (both counted from 1), which is more useful than the raw character offset some browsers report and more reliable than Safari, which reports no position at all. The tool then looks at the surrounding characters to guess the cause: a comma followed by a closing bracket is a trailing comma, a single quote where a string should start is a quoting problem, and so on.

Repair: turning almost-JSON into JSON

Ask a model for "JSON only" and you often get something that is not valid JSON: wrapped in a Markdown code block (three backticks and the word json), introduced with "Sure, here is the result", written with single quotes or Python's True and None, with a trailing comma or a missing one between two properties, or cut off mid-way when the answer ran too long. Repair fixes these at the text level: it strips code fences and surrounding prose, removes comments, converts single quotes to double quotes (escaping inner quotes correctly), quotes bare keys, turns True, False and None into true, false and null and NaN, Infinity and undefined into null, removes extra commas, adds missing ones, and finally closes any unfinished strings and brackets (using null when the text stops after a colon).

Repair does not touch the data itself: numbers are kept exactly as written, string contents are unchanged, and // inside a string is not treated as a comment. Every kind of change is listed so you can judge whether the result is what you want. Truncated output in particular becomes valid JSON, but the missing part was never there, so ask the model to produce the full answer again.

Sorting keys

Sorting orders keys by their Unicode code points at every level of nesting, which is the same order most programming languages use by default. It is useful for comparing two JSON files: sort both, then compare them with the text diff tool, and differences in key order no longer show up as changes.

Examples

Formatting {"b":1,"a":[1,2]} with two-space indentation keeps the original key order:

{
  "b": 1,
  "a": [
    1,
    2
  ]
}

Minifying {"b":1,"a":2} with Sort keys switched on gives {"a":2,"b":1}.

Large numbers survive: {"n": 12345678901234567890} minifies to {"n":12345678901234567890}, where a JSON.parse-based tool would print 12345678901234567000. Likewise [1.0, 1e3, -0.10] stays [1.0,1e3,-0.10].

An error example — this input has a trailing comma after the last property:

{
  "a": 1,
}

The tool reports line 3, column 1, the position of the closing brace, and explains that trailing commas are not allowed. For {a: 1} it reports an unquoted key; for {'a': 1} it reports single quotes at column 2.

Statistics: {"a":{"b":[1,{"c":2}]}} has 3 keys and a nesting depth of 4 (the outer object, the object under "a", the array under "b" and the object inside it).

A repair example. This is typical model output:

```json
{'ok': True, 'items': [1, 2,], name: None}
```

Repair turns it into {"ok": true, "items": [1, 2], "name": null} and lists five kinds of change: code fences removed, single quotes changed, Python literals changed, a trailing comma removed and a key quoted. The truncated {"items": [1, 2 becomes {"items": [1, 2]}.

Limits

  • Formatting and validation accept strict JSON only. JSON5, JSONC (JSON with comments) and JavaScript object literals are reported as errors, so you know whether a strict parser will accept the text. Use Repair to convert; it covers the common cases listed above but is not a full JSON5 parser, so hexadecimal numbers and multi-line strings are not converted.
  • Duplicate keys. RFC 8259 says keys "should" be unique but does not forbid duplicates. When a key appears twice in one object, the formatted output keeps the last value, which is also what JSON.parse does. If duplicates matter to you, check the input before formatting.
  • Only the first error. Parsing stops at the first problem. Fix it and format again to find the next one.
  • Very deep nesting. Documents nested more than 2,000 levels deep are rejected rather than crashing the page.
  • Size. Tens of megabytes work on a desktop browser; a phone may run out of memory on files of that size.

Frequently asked questions

Is it safe to paste API responses or tokens here?

The formatter runs entirely in your browser and makes no network request with your input, so the data does not leave your device. As with any secret, clear the box when you are done.

Why does my JSON say "trailing comma" when it works in JavaScript?

JavaScript object literals allow a comma after the last item; JSON does not. Remove the final comma in the object or array and it will parse.

Will formatting change my numbers?

No. Numbers are copied exactly as written, including integers larger than 2^53, trailing zeros such as 1.50 and exponents such as 1e3.

ChatGPT gave me JSON that does not parse. What now?

Click Repair. It removes code fences and extra prose, fixes single quotes, comments, trailing commas and Python literals, closes truncated brackets, and lists what it changed.

Can it validate against a JSON Schema?

Not yet. This tool checks syntax — whether the text is valid JSON — but not whether the data has the fields and types a particular schema expects.

What is the difference between formatting and minifying?

Formatting adds line breaks and indentation so people can read the structure. Minifying removes all unnecessary whitespace to make the text as short as possible. Both produce the same data.

Sources and further reading

Guides that use this tool

↵ to open · Esc to close