---
title: "Discussion on \"Streaming vs JSON: Trade-offs in AI-Powered Apps\" | Hashnode"
description: "Discussion on \"Streaming vs JSON: Trade-offs in AI-Powered Apps\". A practical breakdown of choosing between streaming and structured JSON responses for AI API calls in a Next.js app."
url: "https://hashnode.com/posts/streaming-vs-json-trade-offs-in-ai-powered-apps/6aae34eb8745becb3c92cdee"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Streaming vs JSON: Trade-offs in AI-Powered Apps](https://david-essien.hashnode.dev/streaming-vs-json-trade-offs-in-ai-powered-apps?utm_source=hashnode&utm_medium=feed)

A practical breakdown of choosing between streaming and structured JSON responses for AI API calls in a Next.js app.

Sep 19 · 4 min read · david-essien.hashnode.dev  
Read the article

-   [#ai](https://hashnode.com/tag/ai)
-   [#webdev](https://hashnode.com/tag/webdev)
-   [#backend](https://hashnode.com/tag/backend)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#llm](https://hashnode.com/tag/llm)
-   [#learning](https://hashnode.com/tag/learning)

## Written by

[David Essien](https://hashnode.com/@davidessien)

@davidessien · Lagos, Nigeria

  
[View profile](https://hashnode.com/@davidessien)

Software engineer writing about systems, security, and the code behind them.

I write about backend architecture and the practical decisions behind shipping production systems — authentication and security patterns in NestJS, AI model integration, and lately Solana-based fintech infrastructure. More to come. Mostly notes from things I've actually built and broken, not theory for its own sake.

## Responses 2

Markdown supported · ⌘↵ to post

[Mihai\_LeanZero](https://hashnode.com/@mihaileanzero)

[Sep 20](https://hashnode.com/posts/streaming-vs-json-trade-offs-in-ai-powered-apps/6aae34eb8745becb3c92cdee/comment/6aafc41ac7b2c1ff0948ed9e)

The extractJSONFromMarkdown fence-stripping caught my eye. It only strips when the string starts with the literal "`json", but you say right above it that the model wraps its answer in a fence about half the time regardless of what you ask for. If it ever emits a bare ` fence without the json tag, that startsWith check misses it, JSON.parse chokes on the leading backticks, and I don't see a try/catch anywhere around that call, so it looks like that would throw straight through, right on the authenticated persist path where you actually need the data to land. A regex like /^\`\`\`(?:json)?\\n?/ instead of the literal startsWith would catch both cases without adding much code.

[David Essien](https://hashnode.com/@davidessien)

[Sep 20](https://hashnode.com/posts/streaming-vs-json-trade-offs-in-ai-powered-apps/6aae34eb8745becb3c92cdee/comment/6aafc41ac7b2c1ff0948ed9e#reply-6aafe970e1ecda497112eae7)

Yeah you're right, the check is a literal match on the json tag, so a bare fence slips past it and breaks the parse. However, the blog post is a simplified reconstructed version of my actual production code, so it does not fall straight through. Fixing the bare fence bug with your suggested regex. Thank you very much.
