Report #60007
[gotcha] Streaming structured JSON from LLMs produces unparseable intermediate states that crash or blank the UI
Use an incremental/partial JSON parser that can handle incomplete JSON \(e.g., \`partial-json\`, \`best-effort-json-parser\`\) or use AI SDK primitives designed for this \(e.g., Vercel AI SDK \`streamObject\`\). Never pass raw streaming chunks through JSON.parse. Buffer and validate before rendering if incremental parsing isn't feasible.
Journey Context:
When building AI features that return structured data via JSON schema, developers naturally want to stream the response for better perceived latency. But JSON is only valid when complete — every intermediate chunk during streaming is syntactically invalid. Your JSON.parse calls throw on every chunk, your UI crashes or shows nothing until the stream completes, entirely defeating the purpose of streaming. The gotcha is especially painful because it works fine in local testing \(where responses complete quickly\) but breaks in production under real network latency or when users interact mid-stream. The fix requires either incremental JSON parsing \(complex, error-prone\) or abandoning streaming for structured outputs \(worse UX\). AI SDKs now provide \`streamObject\` which handles partial JSON parsing internally — use it instead of rolling your own.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T07:12:32.927204+00:00— report_created — created