Repair broken JSON and fix invalid JSON from ChatGPT

Paste almost-JSON from a chat reply, a log or a config. Get strict JSON back and a list of every fix, with line and column.

How it works

  1. Paste the broken JSON or the whole chat reply
  2. Pick the output layout
  3. Copy the repaired JSON and check the fix list

What gets repaired

JSON repair rewrites almost-JSON, such as a chat reply with a code fence, a trailing comma, single quotes or Python's True and None, into strict JSON that JSON.parse accepts. The parser reads your text and fixes these things: a ```json fence and any prose before or after the data, // and /* */ comments, trailing and doubled commas, single-quoted and curly-quoted strings, unquoted keys, True, False and None, a missing comma between two items, a missing colon, line breaks and tabs typed inside a string, a stray backslash such as the one in C:\Users, an unescaped quote inside a string, 0x1F and +5 style numbers, and placeholders like ... in a list. Numbers you wrote keep their digits, so an id such as 12345678901234567890 is not rounded, and keys keep their order.

Cut-off output, NaN and duplicate keys

When a reply stops in the middle, the tool closes every open string, array and object and tells you the text was cut off. Take {"a": 1, "b": [2, 3 as an example: it becomes {"a":1,"b":[2,3]} after 2 fixes, and the end of the data may be missing. A key or value that was cut off completely is dropped instead of invented. NaN, Infinity, -Infinity and undefined do not exist in JSON, so each becomes null, and the notice counts them. If a key appears twice, the last value is kept in the position of the first, which is what JSON.parse does, and the fix list marks it. A broken file with several repairs is easy to check: {name: 'Ada', active: True, tags: ['a', 'b',]} gives 8 fixes, and the list names each one with its line and column.

What it guesses and what it refuses

Two repairs are guesses. A quote inside a string is treated as part of the text when the next character on that line is a letter, as in "She said "hello" to me"; a quote followed by a comma, colon, bracket, digit or another quote ends the string. A missing comma is added when the next thing looks like a key or a value. A bare word such as ok in {"status": ok} is not turned into a string, and text that no repair can read stops with the line and column of the problem. If your reply holds several objects, only the first object or array is kept. Input is limited to 500,000 characters and 500 levels of nesting, and the result is checked with JSON.parse before it is shown.

Using it with AI replies and agents

Chat models and coding agents often return JSON inside a code fence, with a sentence before it, or with a comma left after the last item, and a program that calls JSON.parse on that reply fails with an error such as Unexpected token at position 214. Paste the whole reply here, and the repaired text and the fix list appear in the same page, so a person or an agent can see what was changed before using it. The tool checks syntax only. It cannot tell whether a repaired value is the one the model meant, so read the fix list when a cut-off or a guessed quote is reported, and ask the model for the missing part if the notice says the text ended early.

Frequently asked questions

How do I fix invalid JSON from ChatGPT?

Paste the whole reply, including the line before the code block. The tool removes the ```json fence and the surrounding sentences, then fixes the usual faults such as a trailing comma after the last item, single quotes or True instead of true. The Fixes made box lists each change, for example 11:28 Removed a trailing comma.

Why does JSON.parse say Unexpected token at position 214?

Position 214 is the 215th character of your text, and something there is not valid JSON, often a comma before a closing bracket, a quote that is not a straight double quote, or the opening line of a chat reply. This tool reports every such spot as line and column, fixes it, and shows strict JSON that JSON.parse accepts.

How does it repair JSON that was cut off?

It closes each open string, array and object at the end of the text, so {"a": [1, 2 becomes {"a":[1,2]}. A key with no value at the end is removed. The notice says the text looks cut off, because the closed brackets only make the syntax valid. The data that never arrived is still missing.

Why did NaN become null?

JSON has no NaN, Infinity or undefined, so a strict parser rejects them. The tool writes null for each one and counts them in the notice, for example 2 values became null. If your program needs the original meaning, handle those fields before you trust the result.

What happens when a key appears twice?

The last value wins and the key stays in the position of its first appearance, the same as JSON.parse. For {"a": 1, "b": 2, "a": 3} the result is {"a":3,"b":2}, and the fix list shows a line saying a duplicate key was found.

Is my JSON uploaded?

No. It is processed in your browser, in this tab, and no server receives it. Your choice of output layout is saved in this browser, the text is not.