DEV Community

AI JSONMedic
AI JSONMedic

Posted on

I built a JSON repair tool for LLM output — here's why it exists

You ask an LLM for JSON. You get this:

Enter fullscreen mode Exit fullscreen mode


json
{
"name": "test",
"valid": True,
"items": [1, 2,

Enter fullscreen mode Exit fullscreen mode


markdown

Three problems in one response: markdown fences the LLM was not supposed to add, True instead of true (Python literal), and the response was cut off mid-array.

JSON.parse() throws on all three. A linter tells you what is wrong. But you are left fixing it manually.

I kept hitting this wall so often that I built a dedicated repair pipeline: AI JSONMedic.

Why existing tools do not cut it

JSONLint / JSONFormatter — great for valid-ish JSON with one missing comma. Not built for LLM failure modes: they flag errors but do not repair them.

jsonrepair (npm) — solid library, handles many cases. AI JSONMedic actually uses it as a last-resort fallback. But it does not tell you what it changed, and does not handle all the LLM-specific cases we needed.

The 14 failure modes we target

Through building this, we catalogued how LLMs specifically break JSON:

  1. Markdown fences — backtick-json wrapping the output
  2. Trailing commas[1, 2, 3,] (model runs out of items but adds one more comma)
  3. Python literalsTrue, False, None instead of true, false, null
  4. Single quotes{'key': 'value'} instead of double quotes
  5. Smart quotes — curly quotes from copy-paste
  6. Unclosed brackets — truncated at max_tokens mid-array or mid-object
  7. Unclosed strings — a string value without its closing quote
  8. Concatenated objects{"a":1}{"b":2} when streaming produces multiple chunks
  9. NDJSON — newline-delimited JSON that needs wrapping
  10. Python-style comments# this is a comment inside JSON
  11. JavaScript-style comments// inline or /* block */
  12. Escaped backslashes — double-escaped where single was needed
  13. Duplicate keys — same key appearing twice (we warn, not silently pick)
  14. BOM / encoding issues — UTF-8 BOM at start of response

What makes the repair pipeline different

Each pass targets one failure mode. The order matters — strip fences first, then normalize quotes, then fix commas, then close truncated structures. Each change is tracked.

The result is not just a fixed JSON blob — it is a diff showing exactly what changed:

Removed markdown code fence
Converted Python literal: True to true
Closed truncated array (added missing ])
Enter fullscreen mode Exit fullscreen mode

That explanation is half the value when you are debugging a production pipeline.

100% client-side

The repair runs entirely in your browser. Your production payloads never leave your machine. Open the Network tab — there is no request for the repair itself.

JSON Studio

Beyond repair, there is a full JSON toolbox:

  • Format / minify
  • Validate with error highlighting
  • Tree view
  • Diff two JSON blobs
  • Convert: JSON to CSV, YAML, XML, SQL
  • JSONPath query
  • JSON Schema generation
  • TypeScript type generation
  • JWT decode

Launching on Product Hunt tomorrow (July 23)

We are going live on Product Hunt tomorrow. If you find it useful — or find broken JSON it does not handle — drop a comment.

AI JSONMedic on Product Hunt →

And if you paste in broken JSON that beats the repair engine, I will add a pass for it.

Top comments (0)