{"slug": "stop-wrestling-with-broken-json-from-your-llm", "title": "Stop wrestling with broken JSON from your LLM", "summary": "A developer built and launched LLM Dev Utilities, a RapidAPI-hosted service that repairs malformed JSON returned by large language models, handling code fences, single quotes, trailing commas, Python-style booleans and truncated output. The API returns parsed JSON, a normalized text version and a list of applied fixes, and the developer argues repair should be deterministic parsing rather than a second LLM call that costs tokens and can hallucinate values.", "body_md": "If you've shipped anything on top of an LLM, you know this pain: you ask the model for JSON, and you get back JSON wrapped in a code fence, with a friendly \"Sure! Here's your data:\" in front, single quotes instead of double, a trailing comma, and — on a bad day — the last brace missing because the response got cut off.\n\nSo you write a regex. Then another. Then a try/except that strips fences. Then you discover the model sometimes emits True instead of true. Six months later your \"JSON cleaner\" is 200 lines of defensive string surgery that everyone is afraid to touch.\n\nI got tired of copy-pasting that file between projects, so I turned it into a small API. Here's what it handles and how it works.\n\nReal LLM output that should be JSON tends to break in a predictable handful of ways:\n\nThe first seven are cosmetic. The eighth is the nasty one: you have to walk the string, track the open braces and brackets and whether you're inside a string, and close everything back up in the right order.\n\nSend the broken string; get back valid parsed JSON, a normalized text version, and the list of fixes that were applied. The truncated case is closed automatically — a fragment that starts an object with an unclosed array comes back as a complete, valid object.\n\nYou could send the broken JSON to a second LLM call and ask it to fix it. But that's slower, costs tokens, is non-deterministic, and can hallucinate values that were never there. Repairing JSON is a parsing problem, not a reasoning problem — so it should be solved with a parser. Same input, same output, every time, in milliseconds.\n\nThe same API also has the endpoints I kept needing next to JSON repair:\n\nIf this saves you from maintaining yet another clean_json.py, it's live on RapidAPI with a free tier: [https://rapidapi.com/cesaricf79/api/llm-dev-utilities](https://rapidapi.com/cesaricf79/api/llm-dev-utilities)\n\nWhat's your worst \"the model returned almost-JSON\" story? I'm curious how many of these failure modes I'm still missing.", "url": "https://wpnews.pro/news/stop-wrestling-with-broken-json-from-your-llm", "canonical_source": "https://dev.to/shumai/stop-wrestling-with-broken-json-from-your-llm-3a4h", "published_at": "2026-09-29 09:13:51+00:00", "updated_at": "2026-09-29 09:16:33.138467+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "developer-tools", "ai-products"], "entities": ["RapidAPI", "LLM Dev Utilities"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/stop-wrestling-with-broken-json-from-your-llm", "markdown": "https://wpnews.pro/news/stop-wrestling-with-broken-json-from-your-llm.md", "text": "https://wpnews.pro/news/stop-wrestling-with-broken-json-from-your-llm.txt", "jsonld": "https://wpnews.pro/news/stop-wrestling-with-broken-json-from-your-llm.jsonld"}}