Report #47302
[gotcha] Streaming structured JSON output produces unparseable fragments at each SSE chunk
Use an incremental/streaming JSON parser \(e.g., \`partial-json\`, \`json-stream\`\) that can handle incomplete documents, or design your schema so critical fields appear first and can be regex-extracted before the JSON closes. For small payloads, buffer until complete and skip streaming the response body entirely.
Journey Context:
Developers enable streaming for perceived responsiveness, then add JSON mode or structured outputs for reliability. The combination is the gotcha: each SSE chunk contains a token fragment that, concatenated so far, is syntactically invalid JSON. Standard \`JSON.parse\(\)\` throws on every intermediate chunk. The naive fix—waiting for the full response—defeats the purpose of streaming. The real solution depends on payload size: for large structured responses, use a streaming JSON parser that yields partial objects; for small ones, accept the latency hit and buffer. OpenAI's own structured outputs documentation notes this limitation explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:52:40.907799+00:00— report_created — created