Report #42169
[gotcha] Streaming JSON or structured output cannot be parsed incrementally, breaking real-time UI rendering
Use a partial/incremental JSON parser \(e.g., \`partial-json\`, \`jsonrepair\`\) that can handle incomplete JSON, or buffer the full stream and parse only on completion. For OpenAI structured output with streaming, accumulate delta objects and reconstruct the full object—never attempt \`JSON.parse\(\)\` on an incomplete buffer.
Journey Context:
The promise of streaming is showing results as they arrive. But when your response is JSON \(for structured data, function calls, tool use\), each streamed chunk is a fragment of invalid JSON. Attempting to parse each chunk throws errors. The naive approach—waiting for the full response—defeats the purpose of streaming. The sophisticated approach uses incremental JSON parsers that tolerate truncated JSON, but these are complex and can misinterpret structure. OpenAI's structured output with streaming provides delta objects, but you must still accumulate them before rendering structured UI. The real gotcha: developers often don't discover this until they've already built their streaming text UI and then try to layer on structured output, at which point the architecture doesn't support it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:15:17.894859+00:00— report_created — created