Skip to content

JSON Repair

JSON repair in one click: paste broken JSON, press Repair JSON, and quotes, commas, comments, code fences and cut-off endings are fixed. The result is checked before it replaces your text.

Input · JSON

Invalid JSON

Line 2, column 3

Comments are not allowed in JSON.

1{2  // exported from the admin panel   ^3  name: 'Grace Hopper',

Fix: Delete the comment, or use Repair to strip comments automatically.

Why this happens
Invalid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to repair JSON

  1. Paste the broken text or press Open file. The Report tab shows the first error.
  2. Press Repair JSON or Ctrl + Enter. The editor now holds valid JSON, indented with your Indent setting.
  3. 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, False and None
  • 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 like NumberLong(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", "summ comes back with "summ": null.
  • Windows paths. In "C:\data\new", the invalid \d loses its backslash and \n becomes a line break: "C:data\new". Double the backslashes first.
  • Guesses. NaN and Infinity become strings, undefined becomes null, and 02134 becomes the string "02134". Check that this suits your code.

Common JSON errors explains each parser message.

Questions

Does Repair use AI?

No. It applies fixed rules in your browser, so the same input always gives the same output, and nothing is sent to a model or a server.

What happens if my JSON is already valid?

Repair re-indents it with your Indent setting and leaves the data as it is. If it was already formatted that way, it says there was nothing to repair.

How do I get valid JSON from an LLM in the first place?

Use the structured output or JSON mode of your model API where it has one, leave room under the token limit, and validate each reply before your code uses it.

Related tools

Esc