Report #22395
[gotcha] Streaming structured output produces unparseable partial JSON fragments that crash the UI
Buffer all streaming deltas and only parse the complete JSON on finish\_reason='stop', or use an incremental JSON parser \(e.g., json-stream, partial-json\) that handles incomplete documents. Never call JSON.parse\(\) on intermediate delta content.
Journey Context:
When streaming JSON from an LLM, each SSE chunk delivers a fragment like \{"na → me": → "val"\}. Developers naturally try to JSON.parse each delta to update the UI in real-time, which throws SyntaxError on every chunk. The temptation is to build ad-hoc string repair logic, which is fragile. The correct approach depends on your UX needs: if you need real-time structured updates, use a proper streaming/incremental JSON parser that maintains parse state across chunks. If you only need to display the response and parse at the end, concatenate all deltas and parse once on completion. OpenAI's structured outputs feature guarantees valid JSON on completion but does NOT make intermediate chunks valid — this is the key misunderstanding that burns teams who assume streaming deltas are valid JSON fragments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:00:02.035783+00:00— report_created — created