RealJSON
Try now

JSON Repair — Fix Broken JSON and LLM Output

Paste broken JSON or a whole chatbot answer. Handles Markdown fences, cut-off output, stray quotes, missing commas, Python literals, comments and more.

Broken JSON

Repaired JSON

In short: paste broken JSON — or the entire reply from ChatGPT, Claude, Gemini or a local model — and get valid JSON back, with a list of every fix. It is a tolerant parser rather than a set of regexes, so it repairs the structure without ever rewriting the contents of your strings.

Why LLM JSON breaks

Language models write JSON one token at a time and are trained on JavaScript, Python and Markdown as much as on JSON. The result is output that is almost right: wrapped in a ```json fence with a friendly sentence before it, using True or single quotes, quoting a phrase inside a string without escaping it, or stopping mid-object when the response hits its token limit. One such slip makes JSON.parse throw for the whole response.

What gets fixed

Chat answers and code fences

Text before and after the JSON and Markdown fences are removed; the first JSON object or array is kept.

Here is the data:
```json
{"id": 7}
```
Hope this helps!   →   {"id": 7}

Truncated output

Unfinished strings, arrays and objects are closed; a key with no value is dropped instead of invented.

{"items": [{"id": 1}, {"id": 2, "name": "Wid   →   {"items": [{"id": 1}, {"id": 2, "name": "Wid"}]}

Quotes inside strings

Unescaped double quotes and raw line breaks inside a value are escaped; curly quotes become straight quotes.

{"bio": "Says "hello" a lot"}   →   {"bio": "Says \"hello\" a lot"}

JavaScript and Python syntax

Single-quoted strings, bare keys, trailing or missing commas, True/False/None, NaN, Infinity, undefined and comments are converted to standard JSON.

{name: 'Ann', active: True, score: NaN,}   →   {"name": "Ann", "active": true, "score": null}

Preventing broken JSON in your app

Repair is a safety net, not a contract. In production, ask the model for structured output against a JSON Schema (OpenAI, Anthropic and Gemini all support it), then check the result. Generate that schema from a sample with JSON to JSON Schema, test responses with the JSON Schema Validator, and turn it into typed models with JSON to Pydantic or JSON to Zod.

Features

  • Extracts JSON from chat answers and ```json code blocks
  • Closes truncated output (unfinished strings, arrays, objects)
  • Escapes unescaped quotes and raw line breaks inside strings
  • Inserts missing commas, removes trailing commas
  • Single, curly and unquoted keys → valid double-quoted JSON
  • Python True/False/None and NaN/Infinity/undefined → JSON values
  • Strips //, /* */ and # comments without touching URLs in strings

Frequently Asked Questions

How do I fix broken JSON from ChatGPT or another LLM?

Paste the whole answer — explanation, Markdown code fence and all. The tool pulls out the JSON, repairs it and lists every change it made, so you can see exactly what the model got wrong.

What happens when the model’s output was cut off?

When a response hits the token limit mid-object, the repair closes the unfinished string, array and object so you get valid JSON with everything that was generated. A key whose value never arrived is dropped rather than guessed.

Can it fix quotes inside strings, like "he said "hi""?

Yes. A double quote only ends a string when it is followed by JSON structure (a comma, colon, bracket or line break); otherwise it is treated as part of the text and escaped. Curly “smart” quotes are converted to straight ones.

Can it fix JSON copied from a Python dictionary or JavaScript object?

Yes. Python’s True, False and None become true, false and null; single-quoted strings and bare keys are converted to double-quoted JSON; NaN, Infinity and undefined become null; trailing and missing commas are fixed.

Will removing comments break URLs in my data?

No. The repair is a real parser, not a search-and-replace: //, /* */ and # comments are only removed outside strings, so a value like "https://example.com" is left intact.

Is my JSON sent to a server or to an AI to be repaired?

No. The repair runs entirely in your browser with deterministic code — no upload and no model call. For agents and scripts, the same repair is available offline through the RealJSON MCP server.

Related Tools

After repairing, confirm the result with the JSON Validator, pretty-print it with the JSON Formatter, or check model-generated training data with the Fine-Tuning JSONL Validator.

Browse all free JSON tools →