Report #26444
[gotcha] streaming structured JSON output causes parse errors in UI
Use incremental/partial JSON parsing \(e.g., partial-json library\), or design your output schema so early fields are independently renderable, or use OpenAI's structured outputs streaming mode which emits complete schema fields incrementally; never naively parse accumulated streaming chunks as complete JSON
Journey Context:
Streaming tokens delivers great UX by reducing perceived latency, but structured output \(JSON\) requires syntactically valid input to parse. The naive approach — accumulate chunks and JSON.parse — fails because every intermediate state is invalid JSON \(truncated strings, missing braces, dangling commas\). You are forced into a false binary: buffer everything \(killing streaming UX\) or write a fragile incremental parser. The right pattern is a partial JSON parser that can resolve truncated input, combined with schema design that front-loads renderable fields. OpenAI's structured outputs with streaming partially addresses this by emitting complete fields as they finish, but you still need client-side handling for partially-arriving nested objects. Teams discover this only when their streaming UI works for simple strings but crashes on structured output.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:47:09.724866+00:00— report_created — created