JSON Extractor from LLM Response

Pull JSON objects or arrays out of verbose LLM prose.

Scan a messy LLM response and extract every JSON object and array it contains — inside markdown fences, buried in prose, or across multiple code blocks. Each valid block is returned separately, pretty-printed, and copyable, all in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How does it find JSON inside prose?

It scans the text for balanced brace and bracket spans, tracking string literals so braces inside strings do not confuse the matcher. Each candidate span is run through a real JSON parser, and only spans that parse are returned, so explanatory prose is ignored automatically.

JSON extractor from LLM response

When a model returns JSON, it often buries it: a paragraph of explanation, a markdown code fence, the JSON, then more commentary — sometimes several blocks in one reply. This tool reads the whole response and pulls out every valid JSON object and array it can find, returning each one cleanly so you can copy exactly what you need.

How it works

The extractor scans the text for balanced spans that start with { or [. It walks character by character, tracking whether it is inside a string literal so that braces appearing inside string values never throw off the brace count. When a span is balanced, it is run through JSON.parse; only spans that parse successfully are kept. The result is a list of pretty-printed blocks, each independently copyable, with prose and invalid fragments silently skipped.

Why LLM responses need special handling

Even when you instruct a model to “respond only with JSON,” most models add something extra:

  • A markdown code fence (```json ... ```) because the model was trained to format code that way.
  • A short preamble like “Here is the requested data:” before the JSON.
  • An explanation or caveat after the JSON explaining what it returned.
  • Multiple separate JSON objects if you asked for several things at once.

Trying to strip these with a regular expression is fragile — a quote or brace inside a string value can break naive patterns. This tool uses a character-level parser that properly handles string literals, so it reliably finds exactly the JSON content no matter how it is wrapped.

What gets extracted

The tool finds and returns every top-level JSON object ({ ... }) and JSON array ([ ... ]) in the response, in the order they appear. Inner nested objects that are part of a larger object are not extracted separately — only the outermost balanced spans at the root level of the response text are returned.

For example, a response like:

Sure, here are the results:

```json
{"name": "Alice", "score": 42}

And here is the summary:

[{“category”: “A”}, {“category”: “B”}]


produces two separate extracted blocks: the object and the array.

## Notes and tips

- **Strictly valid only.** Malformed blocks are skipped on purpose — run them
  through the LLM JSON Repair tool first if you need them.
- **Multiple blocks are separated.** One response with three objects gives you
  three copy buttons, not one tangled blob.
- **Order is preserved.** Blocks appear in the order they occur in the response,
  so the first match is the first object the model wrote.
- **Everything stays local.** The scan runs in your browser; paste freely.
- **For pipelines:** if you are building an automated pipeline, use the model's native JSON mode or structured-output feature when available. This extractor is most useful for interactive debugging and manual workflows.