LLM JSON Extractor

Paste a raw response from ChatGPT, Claude, Gemini or any local model. The extractor finds the JSON inside it, repairs the usual LLM mistakes and hands you clean, valid JSON. Everything runs in your browser.

LLM response
Press Ctrl + Enter to extract
Valid JSON

How it works

  1. Strip the wrapperRemoves <thinking> and <reasoning> blocks, then looks inside markdown code fences first.
  2. Find the JSONScans for balanced objects and arrays, skipping brackets that appear inside strings or in the surrounding prose.
  3. Repair itFixes trailing and missing commas, single quotes, unquoted keys, comments, Python literals and raw newlines in strings.
  4. Close truncationIf the model hit its token limit mid-object, open strings and brackets are closed and any half-written key is dropped.

Why LLM output breaks JSON.parse

Language models are trained on a lot of JavaScript, Python and Markdown, so their "JSON" often borrows habits from those languages: True and None from Python, trailing commas and // comments from JavaScript, and a friendly "Here is your JSON:" sentence before a fenced code block. Long responses can also be cut off when they reach max_tokens, leaving an object with no closing brace. A strict parser rejects all of these, which is why a pipeline that works in testing can fail on one response in a hundred in production.

This tool is the quick way to recover a single response while you debug. For production, the reliable fix is to stop asking the model for free-form JSON at all: use tool use or structured outputs so the provider constrains generation to your schema, then validate the result with the JSON Schema Validator.

What gets repaired

  • Markdown code fences (```json) and explanatory text before or after the data
  • Reasoning tags such as <thinking>, <think> and <reasoning>, including any JSON-like drafts inside them
  • Single-quoted and smart-quoted strings, unquoted keys and bare string values
  • True, False, None, NaN, Infinity and undefined
  • Trailing commas, missing commas between items, and //, /* */ or # comments
  • Unescaped line breaks inside strings and invalid backslash escapes
  • Truncated output: unterminated strings, dangling keys and unclosed brackets

Frequently asked questions

Is my data sent anywhere?

No. Extraction and repair run in JavaScript on this page. Nothing you paste is uploaded, logged or stored.

Which part of the response is used when there are several JSON blocks?

By default the first fenced block labelled json is used, falling back to the first fenced block and then to the largest JSON value found in plain text. Tick "Extract every JSON block" to get all of them as one array, in the order they appear.

Can a repaired result be wrong?

Yes, when the input is badly damaged. Repairs are listed under the output so you can review them. A truncated response is closed so that it parses, but anything the model never wrote is missing. Treat repaired data as a best effort and validate it before using it.

How do I stop getting broken JSON from the model?

Use the provider's schema-constrained features: tool use with strict mode or structured outputs on Claude and OpenAI, or a response schema on Gemini. Our JSON to LLM Tool Schema generator builds those schemas from an example object.

How is this different from the JSON Repair tool?

JSON Repair expects the input to be JSON with syntax errors. The LLM JSON Extractor first has to find the JSON inside a conversational reply, ignoring reasoning blocks, prose and multiple code fences, and it also handles truncation caused by token limits.

Related AI tools