A real-time financial dashboard must stream token-by-token responses from Claude and display partial JSON as the response accumulates. During testing, the SSE stream intermittently delivers malformed partial JSON that crashes the parser before the closing brace arrives. What is the correct architectural pattern to handle this?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — a is correct because SSE delta events deliver token fragments, not semantically complete units — a JSON object can be split across many deltas. The correct pattern is to accumulate all content_block_delta text and parse only after message_stop signals completion.
Full explanation below image
Full Explanation
A is correct because SSE delta events deliver token fragments, not semantically complete units — a JSON object can be split across many deltas. The correct pattern is to accumulate all content_block_delta text and parse only after message_stop signals completion. B is wrong because individual deltas are character fragments, not valid JSON; discarding 'malformed' fragments would discard most of the response. C is wrong because while streaming JSON parsers are a valid approach for very large responses, switching parser mode based on content_block_start is not a reliable signal for JSON content and introduces unnecessary complexity; buffering to message_stop is simpler and correct. D is wrong because disabling streaming is a workaround, not an architectural solution, and sacrifices user experience unnecessarily when proper buffering solves the problem.