Report #26922
[gotcha] Streaming structured JSON output from AI APIs breaks client-side parsers with SyntaxError
Accumulate all streamed delta content before parsing JSON. Only parse on the terminal \[DONE\] event. For progressive UI updates, use a streaming-aware JSON parser \(e.g., partial-json, jsonrepair\) that tolerates incomplete JSON, or extract only the delta field values you need from each chunk without full JSON.parse\(\).
Journey Context:
When streaming is enabled with JSON mode or structured outputs, each SSE chunk contains a partial JSON fragment. Naively running JSON.parse\(\) on each chunk throws because the JSON is incomplete mid-stream. This bites in production because short test responses often complete in a single chunk, masking the bug. The temptation is to disable streaming for structured outputs, but that sacrifices perceived latency. The right call: accumulate-then-parse for correctness, or use a partial JSON parser for progressive rendering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:35:15.303011+00:00— report_created — created