Skip to content

JSON Repair Tool for AI Output

Repair common syntax problems in JSON copied from a model response, including Markdown code fences, trailing commas and single quotes.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is LLM JSON Fixer?

LLM JSON Fixer turns the almost-JSON that large language models produce into strict, valid JSON. When you ask a model for structured output, the reply often arrives wrapped in a ```json markdown fence, preceded by a sentence like "Here is the JSON:", sprinkled with // comments, written with single quotes or Python literals (True, False, None), littered with trailing commas, or cut off mid-object because the response hit its token limit. JSON.parse rejects all of these, which breaks agent pipelines, function-calling handlers and data-extraction scripts.

This tool reads the input with a forgiving parser that understands those mistakes, rebuilds the data, and re-serializes it as standards-compliant JSON (RFC 8259). Every repair is listed with the line where it was first found, so you can see exactly what changed instead of trusting a black box. Input that is already valid passes through unchanged.

The same repairs work on invalid JSON from any source, such as hand-edited config files, JavaScript object literals or JSON pasted from a chat, so you can use it to fix JSON online whatever produced it.

How to use LLM JSON Fixer

  1. Paste the raw model response into the left panel. Leave in the code fences, explanations and any truncated ending; the fixer finds the JSON itself.
  2. The repaired JSON appears instantly on the right, with an interactive tree view for exploring nested data.
  3. Check the repair summary under the workspace to see which problems were fixed and on which line each one first appeared.
  4. Use the Indent button to switch between 2-space, 4-space and minified output.
  5. Copy the result or download it, then feed it back into your code, prompt or test fixture.

Key features

  • Extracts JSON from markdown code fences and surrounding chatty prose
  • Fixes single quotes, curly smart quotes, unquoted keys and unescaped inner quotes
  • Removes trailing commas and comments; inserts missing commas and colons
  • Converts Python True/False/None and JavaScript undefined/NaN/Infinity
  • Closes strings, arrays and objects left open by truncated (max_tokens) output
  • Unwraps double-encoded and backslash-escaped JSON strings
  • Lists every repair with the line where it first occurred
  • Preserves large integers exactly and leaves valid JSON untouched
  • 100% client-side: deterministic, private and works offline

Common use cases

  • Parsing structured output from ChatGPT, Claude, Gemini, Llama or other models when it fails JSON.parse
  • Recovering usable data from a response that was cut off by the max_tokens limit
  • Debugging function-calling and tool-use arguments that a model returned with syntax errors
  • Converting Python dict reprs or print() output from notebooks into real JSON
  • Cleaning JSON copied from logs, where it was escaped as {\"key\": \"value\"}
  • Turning JSON Lines (one object per line) into a single JSON array

Technical details & standards

The fixer is a deterministic recursive-descent parser, not an AI model, so the same input always produces the same output. It first extracts the body of a ```json fence (closing fences escaped inside JSON strings are ignored), skips any leading or trailing prose, and unwraps payloads that were double-encoded as a JSON string or backslash-escaped (for example {\"a\": 1} copied from a log).

While parsing, it accepts single, backtick and curly quotes; unquoted keys and bare-word values; //, /* */ and # comments; True/False/None and undefined/NaN/Infinity; hex, leading-dot and leading-plus numbers; missing or extra commas and colons; ellipsis placeholders; MongoDB-style wrappers such as ObjectId("..."); Python tuples; and string concatenation. An unescaped quote inside a string is detected by checking what follows it. Valid JSON always closes a string right before a delimiter, so this heuristic never alters input that is already correct. Brackets left open by truncated output are closed in the right order, and several top-level values (JSON Lines) are wrapped in an array.

Numbers are carried through as their original digits instead of being converted to floating point, so 64-bit IDs such as 12345678901234567890 are not rounded the way a JSON.parse round trip would round them. Everything runs locally in your browser; nothing is uploaded or logged.

Fix JSON wrapped in Markdown code fences

A model response can look like JSON but fail JSON.parse because it includes Markdown, single quotes, Python literals or a trailing comma. Repair the syntax, then check the recovered values against the source.

Example input

```json
{'active': True, 'note': None,}
```
  1. Paste the complete response, including the opening and closing Markdown fences.
  2. Review the repair list: fences are removed, single quotes become JSON quotes, True becomes true, None becomes null and the trailing comma is removed.
  3. Compare the repaired values with the source before using them. Closing a truncated object cannot recover fields the model never returned.

Expected result

{"active":true,"note":null}

Continue with a related task:

Frequently asked questions

How do I fix a JSON parse error?

Paste the JSON into the fixer. Errors such as Unexpected token, Expected property name or Unexpected end of JSON input are usually caused by trailing commas, single quotes, unquoted keys, comments, Python literals or missing closing brackets, and the fixer repairs all of them and lists each change. To see where the error is without changing anything, use the JSON Validator.

Why do LLMs return invalid JSON?

Language models generate text token by token and imitate the formats they saw in training, which include JavaScript object literals, Python dicts and markdown code blocks. Without strict structured-output or JSON mode, they often add explanations, comments or trailing commas, and long responses can be cut off by the token limit before the closing brackets are written.

Will the fixer change my data?

Valid JSON passes through unchanged. For broken input, only syntax is repaired: quotes, commas, brackets and literals. Values keep their content, numbers keep their exact digits, and anything ambiguous (such as a bare word like red) becomes a string rather than being dropped. Review the repair summary to see every change.

What happens with truncated JSON?

Open strings, arrays and objects are closed in the correct order, a dangling key gets a null value, and a cut-off true/false/null is completed. The last item may be incomplete because its content was never generated, so check it before using the data.

Is my data sent to an AI service?

No. The repair is done by a deterministic parser running in your browser. Nothing you paste is uploaded, logged or sent to any model.

How is this different from the JSON Formatter or JSON Validator?

The formatter and validator follow the strict JSON standard, so they only tell you where the syntax is wrong. The LLM JSON Fixer repairs those errors for you and then formats the result.

How can I stop getting broken JSON from a model in the first place?

Use the provider's structured-output, JSON mode or tool-calling feature where available, give the model an explicit JSON schema, ask for JSON only with no prose or code fences, and allow enough output tokens for the full response. Keep a repair step like this one as a fallback for the cases that still slip through.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More validators & checkers tools

View all