Report #93395
[gotcha] Streaming structured JSON output breaks parsers because partial JSON is syntactically invalid
For streaming structured output, use one of three patterns: \(1\) Buffer the complete response before parsing—simplest but loses streaming benefit. \(2\) Use incremental streaming JSON parsers \(e.g., ijson for Python, JSONStream for Node.js\) that handle partial input. \(3\) Use SSE with complete self-contained JSON objects per event rather than one large JSON response. Never naively JSON.parse each streaming chunk.
Journey Context:
This is a classic migration gotcha: JSON parsing works perfectly in development with non-streaming complete responses, then breaks in production when streaming is enabled. Each SSE chunk contains a partial JSON fragment that is invalid on its own. The failure is silent—the parser throws, the UI shows nothing, and developers are confused because the same endpoint works without streaming. The fix depends on requirements: buffering is simplest but defeats streaming purpose, incremental parsers preserve streaming at the cost of dependency complexity, and per-event JSON objects in SSE is the cleanest architecture but requires backend changes. The tradeoff is between implementation complexity and real-time feedback, and per-event SSE with complete JSON objects is usually the right architectural choice.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:21:01.906417+00:00— report_created — created