Report #21295
[gotcha] Streaming JSON output from LLMs produces syntactically invalid fragments that crash naive JSON.parse\(\)
Use an incremental/streaming JSON parser \(e.g., partial-json for Python, best-effort JSON parsing for JS\), or use structured output / function calling APIs that handle server-side parsing, or buffer the full response before parsing. Never pass streaming JSON fragments directly to JSON.parse\(\).
Journey Context:
The temptation is to stream JSON for progressive UI updates — filling in form fields or table rows as they are generated. But JSON is not a streaming format: \`\{"name": "Al\` is invalid and will throw in JSON.parse\(\). This silently breaks in production because during development you test with short responses that complete quickly, but longer responses in production hit the parser mid-stream. The error looks like a random parse failure, not a fundamental architectural mismatch. Function calling and structured output APIs from OpenAI and Anthropic solve this by parsing server-side, but they sacrifice the progressive-rendering UX. If you need both streaming UX and structured data, you need incremental parsers that can handle partial JSON — a non-trivial requirement that most teams discover only after their first production outage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:08:48.567067+00:00— report_created — created