# Online JSON Repair: Fix Broken JSON and JSON5 | JSON5.dev


Source: https://json5.dev/tools/online-repair/

---

# Online JSON Repair: JSON5

Fix broken JSON, JSON5 and model output, and see every edit that was made.

Some text is not valid JSON and not valid JSON5 either: a comma is missing, the text stops halfway through a string, it is wrapped in a Markdown code fence, or it uses Python's `True` and `None`. A validator can only tell you where it fails. This tool repairs it and gives you strict JSON.

A repair is a guess, so the tool shows its work. Every character it added is marked in green and every character it removed is struck through in red. Read the edits before you trust the result. Everything runs locally in your browser and your text is never uploaded.

![Broken JSON with a missing comma and an open string on the left, repaired strict JSON on the right](https://json5.dev/img/hero/tools-online-repair.png)

**TL;DR:** Paste text that will not parse. The output box holds repaired, strict JSON, and the panel under it marks each edit. If the input was already valid JSON5, nothing was guessed and the tool says so. If it was not, check the edits: a repair can change what the data means.

## Repair JSON

A broken sample is loaded: a code fence, an unquoted key, Python constants, a missing comma and a cut-off string. Replace it with your own text.

Broken input

Repaired JSON

     

Edits made by the repair

**Private by design:** the repair runs in your browser. Your text is never uploaded, logged or sent to any server, and it is gone when you close the tab. Open file and drag and drop read the file inside your browser. Copy link puts the text in the part of the address after the # sign, which browsers do not send to any server.

![Settings icon](https://json5.dev/images/icons/settings.png)

## How the Repair Works

The tool takes three steps, and stops at the first one that succeeds.

1.  **Strict JSON first.** The text goes through the browser's own `JSON.parse`. If that works, there is nothing to repair and the text is returned unchanged.
2.  **JSON5 second.** The reference JSON5 parser tries the text. If it accepts it, the input was a correct JSON5 document, and rewriting it as JSON involves no guessing. The status line tells you this.
3.  **Repair last.** The text is handed to `jsonrepair`, an open source library by Jos de Jong (ISC license) that is bundled into this page. It walks the text once and inserts, removes or rewrites characters until the result is valid JSON.

The repaired text is then parsed with `JSON.parse` one more time before it is shown, so the output box never holds text that a JSON parser would reject. If the library cannot make sense of the input, you get its error with the line and column instead.

The edit panel compares the input and the output character by character. It is drawn for inputs up to 20,000 characters; above that the output is still produced but the panel is skipped to keep the page responsive.

![Checklist icon](https://json5.dev/images/icons/checklist.png)

## What It Can Fix

These are the defects the built-in sample contains, with what the repair does to each. Load the sample and you can see every row in the edit panel.

Defect in the input

What the repair does

Is it a guess?

A sentence before the data, such as "Here is the config"

Keeps it as a string. The result becomes an array that holds the sentence and then the data.

Yes, and usually not what you want. Delete the sentence first.

A Markdown code fence around the data

Removes the fence lines

No

Unquoted key, single-quoted string

Adds or swaps to double quotes

No. This is valid JSON5.

Python `True`, `False`, `None`

Writes `true`, `false`, `null`

Small. The meaning is clear.

Trailing comma

Removes it

No. This is valid JSON5.

Missing comma between two members

Inserts a comma

Yes. It assumes two members were meant.

Text that stops in the middle of a string, array or object

Closes the string and every open bracket

Yes. The missing part is simply gone.

Comments

Removes them

No. This is valid JSON5.

The library handles more cases than this table lists; its own documentation is the reference. The rule for reading the result stays the same: an edit in a row marked "Yes" needs your eyes.

![Warning icon](https://json5.dev/images/icons/warning.png)

## Repair Is a Guess, Validation Is Not

A validator answers a yes or no question from the grammar. A repair tool answers a different question: what is the nearest valid text? There is often more than one answer, and the tool picks one without telling you there were others.

-   **Cut-off text loses data.** If a response stopped after 3 of 10 array items, the repaired array has 3 items and parses cleanly. Nothing in the output says 7 are missing.
-   **A closed string may be half a value.** `"note": "cut off here` becomes a complete string that ends where the text ended.
-   **The result is JSON, not JSON5.** Comments are removed, hexadecimal numbers are written in decimal, and the layout of the input is mostly kept but not guaranteed.
-   **Valid syntax is not a valid document.** After a repair, check that the required keys exist and have the right types. The [schema validator](https://json5.dev/tools/online-schema-validator/) does that in the browser.

For a config file a person wrote, do not repair it: use the [validator](https://json5.dev/tools/online-validator/), read the line and column, and fix the cause. Repair is for text you cannot ask the author to fix, such as output from a language model or a log line that was truncated. The tutorial on [parsing model output](https://json5.dev/tutorials/llm-json-output/) shows the same parse-first, repair-second order in code.

## FAQ

### What is the difference between this and the validator?

The validator tells you whether text is valid JSON5 and where it fails. It never changes the text. This tool changes the text until it is valid JSON and shows you what it changed.

### Can it fix JSON from a language model?

Usually, for the common problems: a code fence around the data, single quotes, [trailing commas](https://json5.dev/glossary/#trailing-comma), Python constants and a response that was cut off. It cannot restore the part of a cut-off response that was never produced, and a sentence before or after the data is kept as a string, so delete it first.

### Why is the output JSON and not JSON5?

The repair library targets strict JSON, which every language can read. To get JSON5 back, paste the result into the [converter](https://json5.dev/tools/online-converter/) and choose JSON to JSON5.

### Is my text uploaded anywhere?

No. The repair library is part of the page and runs in your browser tab. Nothing is transmitted or stored.

### Can I use the same repair in my own code?

Yes. The tool uses the `jsonrepair` npm package without changes. Install it with `npm install jsonrepair` and call `jsonrepair(text)`; it returns the repaired string or throws.

## See Also

[

### Online Validator

Find the exact line and column

](https://json5.dev/tools/online-validator/)[

### Parsing Model Output

Parse first, repair second

](https://json5.dev/tutorials/llm-json-output/)[

### Parse Errors

What each message means

](https://json5.dev/troubleshooting/parse-errors/)

## More Online Tools

Check the repaired result against a schema, or compare it with the original.

[Schema Validator](https://json5.dev/tools/online-schema-validator/) [Compare Two Files](https://json5.dev/tools/online-diff/)
