Report #97111
[gotcha] Streaming JSON responses from AI APIs creates invalid partial state that crashes UI parsers
Use streaming-object-aware parsers \(e.g., Vercel AI SDK's useObject, partial-json\) that handle incomplete JSON gracefully, or buffer structured output and render only on complete valid JSON. Never JSON.parse\(\) a streaming response mid-stream.
Journey Context:
Developers naturally want to stream everything for perceived speed. But JSON streaming means your UI receives truncated objects like \{"name": "Al which will throw on JSON.parse\(\). The naive fix—waiting for the full response—defeats streaming entirely. Another naive fix—regex extracting values—is fragile and breaks on nested objects or escaped characters. The right pattern is to use streaming object hooks that maintain a valid partial state tree, or to split your response architecture: stream text for display, buffer and validate structured data before rendering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T21:34:58.177129+00:00— report_created — created