Report #41988
[gotcha] Streaming JSON responses cannot be incrementally parsed, blocking UI rendering of structured AI output
Use a streaming JSON parser that handles incomplete JSON \(e.g., partial-json for Python, @ai-sdk/ui for React\), or restructure output to emit complete JSON objects per SSE event rather than one monolithic blob. For display-only scenarios, stream raw text to the UI while collecting the complete JSON server-side for post-response actions.
Journey Context:
Developers enable streaming for better perceived latency, then discover partial JSON is syntactically invalid and throws on JSON.parse\(\). The naive fix—buffering until complete—defeats streaming's purpose. The tempting hack—manually patching incomplete JSON with closing brackets—breaks on nested objects, escaped quotes, and arrays. This is especially painful with OpenAI's structured output mode, which wraps responses in a single JSON object. The right approach depends on your constraint: if the UI needs structured data to render, use a proper streaming parser or restructure the stream to emit complete fragments; if structured data is only needed for actions after generation, stream raw text for display and parse the complete JSON server-side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:57:06.565676+00:00— report_created — created