{"message": "I'm currently generating your resp
JSON.parse dies. You either wait for the full response (slow) or try to parse incrementally (hard). I wrote a single-pass state machine that repairs broken JSON as chunks arrive.
Technical approach: - Zero external dependencies - everything from scratch - No regex (avoids ReDoS vulnerabilities) - O(n) single-pass processing - Stack-based context tracking - Character classification via bitmask lookup table - Works in Node.js, Deno, Bun, browsers, Cloudflare Workers
What it handles: - Truncated strings and unclosed brackets - Python constants (None, True, False) - Single quotes, trailing commas, unquoted keys - JSONP wrappers, MongoDB types (NumberLong) - LLM "thinking" blocks and markdown fences - String concatenation ("a" + "b")
The streaming benchmark shows 1.7x faster than jsonrepair - we avoid re-parsing the entire document on each chunk. 7KB minified. TypeScript-first with full type definitions.
Curious what edge cases others have hit - always looking to improve coverage.
dmarwicke•1mo ago
prxtenses•1mo ago
Supported thinking block patterns:
<thinking>...</thinking> (Claude) | <thought>...</thought> (DeepSeek) | <reasoning>...</reasoning> | <scratchpad>...</scratchpad> |
Also handles markdown code blocks and common LLM prose like "Here's the JSON:" or "Hope this helps!"