How to repair JSON
- Paste the broken text or press Open file. The Report tab shows the first error.
- Press Repair JSON or Ctrl + Enter. The editor now holds valid JSON, indented with your Indent setting.
- Check the result before you use it.
If repair fails, the editor stays as it was and a message says where it gave up.
Fix JSON from an LLM
Model output breaks in predictable ways: a Markdown code fence, Python literals, trailing commas, ... in place of the rest of a list, and an ending cut off by the token limit. This reply has all of them:
```json
{
"product": "Trail Runner 2",
"sentiment": 'positive',
"pros": ["grip", "weight",],
"cons": ["sizing runs small", ...],
"would_recommend": True,
"rating": 4.5
```
Repair JSON returns:
{
"product": "Trail Runner 2",
"sentiment": "positive",
"pros": [
"grip",
"weight"
],
"cons": [
"sizing runs small"
],
"would_recommend": true,
"rating": 4.5
}
Copy only the fenced block: a sentence before or after the fence is kept as an extra string, and the result becomes an array.
What JSON repair fixes
- Single quotes, curly quotes and unquoted keys
- Missing commas, and trailing commas such as
{"a": 1,}, which Chrome reports as Expected double-quoted property name in JSON //and/* */comments (see can JSON have comments)- Python’s
True,FalseandNone - Unclosed brackets and strings in cut-off output, where Unterminated string in JSON is the usual symptom
- Raw line breaks inside strings, which become
\n - JSONP wrappers like
callback({...}), MongoDB types likeNumberLong(2), and escaped JSON like{\"id\": 1} - One object per line (NDJSON), which becomes an array
The engine is the open-source jsonrepair library (import { jsonrepair } from 'jsonrepair'). This page strips a Markdown fence before it runs and checks the output with the strict parser of the JSON validator.
What it cannot fix
- Missing data. Cut-off text is closed, not completed:
{"id": 812, "priority": "low", "summcomes back with"summ": null. - Windows paths. In
"C:\data\new", the invalid\dloses its backslash and\nbecomes a line break:"C:data\new". Double the backslashes first. - Guesses.
NaNandInfinitybecome strings,undefinedbecomesnull, and02134becomes the string"02134". Check that this suits your code.
Common JSON errors explains each parser message.