Quick access

Saved in this browser. Sign in to keep it on all your devices.

JSON Repair & LLM Output Validator

Paste JSON from ChatGPT, Claude, or Gemini that will not parse. Get valid JSON back with a list of what was fixed, then check it against your schema. Nothing leaves your browser.

Paste the whole definition; the schema inside it is found for you. Need one? Generate a schema from sample JSON.

Valid JSON appears here as you paste.

✓ Valid JSON. Nothing needed fixing.

Repaired. Fixed:

The reply was cut off, so the last value may be incomplete. Check it before you use the data.

This cannot be repaired automatically.


            
Version 1.1 Updated What's new

Release notes

  1. v1.1 Latest
    • Added an in-depth guide below the tool, written from what the tool actually does.

About the JSON Repair & LLM Output Validator

Language models often return JSON that almost works: wrapped in a ```json fence and a friendly sentence, with a trailing comma, single quotes, Python's True and None, or cut off halfway when the reply ran out of tokens. Paste the answer to get valid JSON back and a list of everything that was fixed, then check it against the schema your code expects.

How to use it

  1. 1 Paste the AI's answer, or any broken JSON.
  2. 2 Read what was fixed, and copy or download the clean JSON.
  3. 3 Optionally paste a JSON Schema, an OpenAI response_format, an Anthropic tool, or a Gemini responseSchema to check the data matches it.

Frequently asked questions

Why does ChatGPT return invalid JSON?

A model writes JSON one token at a time and has no parser checking its work. It can add a trailing comma, use single quotes, write True or None as Python does, add comments, or stop mid-way when it reaches its output limit. Structured outputs reduce this, but plain prompts still slip.

What can the tool repair?

Markdown code fences and text around the JSON, trailing and missing commas, single and curly quotes, unquoted keys, comments, Python and JavaScript values such as True, None, and undefined, line breaks inside strings, JSON encoded inside a string, several values in a row, and output that was cut off. It lists every kind of fix it made.

Can it finish JSON that was cut off?

It closes any open strings, arrays, and objects so the JSON parses, but it cannot know what the model would have written next. The last value may be incomplete, so check it, or ask the model to continue with a higher output token limit.

Which schema formats can I paste?

A plain JSON Schema, an OpenAI response_format or Responses text.format with json_schema, an OpenAI function or tool, an Anthropic tool with input_schema, or a Gemini responseSchema or responseJsonSchema. Paste the whole definition and the tool finds the schema inside it.

Is my data sent to a server?

No. Repair and validation run in your browser, so your JSON never leaves your device.

Six ways model output breaks JSON

  • A chatty wrapper: “Sure! Here is the data:” followed by a ```json fence and a closing remark.
  • A trailing comma after the last item, as in {"a": 1, "b": 2,} — legal in JavaScript, not in JSON.
  • Python values: True, False and None instead of true, false and null, often from a model that was just writing Python.
  • Single or curly quotes, such as {'name': ‘Rina’}, which happen when the text passed through a word processor or chat app.
  • A raw line break inside a string value. JSON needs \n written out instead.
  • A reply that stops mid-object because it reached its max output tokens, leaving brackets and a string open.

Each of these makes JSON.parse or json.loads throw, even though the data a person reads is clear. The repair step fixes all six and reports which ones it found, so you can see whether the model needs a better prompt.

A JSON validator tells you; a repair tool changes the text

A validator, checker or linter only answers one question: does this parse, and if not, at which line and column does it fail? That is the right tool when you wrote the JSON by hand and want to fix it yourself. Repair goes further and rewrites the text into valid JSON. Use repair for machine output you did not write, and read the list of fixes before trusting the result. To find a single typo in a config file, the JSON Formatter points at the exact position instead.

Repair JSON inside your own code

This page uses the open-source jsonrepair library. The same fixes are available in your code, so a pipeline does not crash on one bad reply:

// JavaScript: npm install jsonrepair
import { jsonrepair } from 'jsonrepair'
const data = JSON.parse(jsonrepair(reply))

# Python: pip install json-repair
import json_repair
data = json_repair.loads(reply)

Log every reply that needed repair. A sudden rise usually means a prompt change or a new model version, and it is cheaper to catch that early than to debug missing fields later.

Ask for valid JSON in the first place

  • OpenAI: use structured outputs with a json_schema response format and strict set to true.
  • Anthropic: define a tool with an input_schema and ask Claude to call it, so the arguments arrive as JSON.
  • Gemini: set responseMimeType to application/json and pass a responseSchema.
  • Any model: raise the output token limit for long lists, and ask for the JSON only, with no explanation around it.

Even with these settings, keep the schema check. Valid syntax does not mean the right fields: a model can still return a string where your code expects a number, or leave out a required key. The validation step on this page catches exactly that.