Report #96273
[gotcha] Streaming structured JSON output breaks client-side parsing mid-flight
Use incremental JSON parsing \(e.g., \`partial-json\` library\) or buffer the full stream and parse only after the \`\[DONE\]\` event. For OpenAI structured outputs, check the \`refusal\` field in the final chunk before using the parsed object.
Journey Context:
When streaming, each SSE chunk contains a fragment of the JSON object. Naive \`JSON.parse\(\)\` on each chunk throws a SyntaxError because the JSON is incomplete. Developers either give up on streaming \(defeating its UX purpose\) or try regex-based extraction \(fragile and error-prone\). The right approach is incremental parsing libraries that handle partial JSON, or buffering with a clear completion signal. OpenAI's SDK handles this internally, but raw API consumers hit this immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:10:43.081550+00:00— report_created — created