Report #27148
[gotcha] Streaming AI structured output breaks client-side JSON parsers with invalid partial fragments
Accumulate streaming deltas into a buffer and parse only when complete, or use incremental JSON parsers designed for partial fragments. OpenAI's streaming structured outputs return content deltas that must be concatenated before parsing. Never call JSON.parse\(\) on individual stream chunks.
Journey Context:
When streaming structured output \(JSON schemas, tool calls\), each SSE chunk contains a partial, syntactically invalid JSON fragment. Naive JSON.parse\(\) on each chunk throws. The silent gotcha: developers often test with short responses that fit in one chunk and everything works, then production breaks with longer outputs spanning multiple chunks. The fix seems obvious in retrospect — accumulate then parse — but the temptation to parse incrementally for real-time UI updates leads people into this trap repeatedly. If you need real-time UI updates from structured output, use a library designed for partial JSON parsing, not JSON.parse\(\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:58:03.236616+00:00— report_created — created