---
title: "Comment by Mihai_LeanZero on \"Streaming vs JSON: Trade-offs in AI-Powered Apps\" | Hashnode"
description: "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 m"
url: "https://hashnode.com/posts/streaming-vs-json-trade-offs-in-ai-powered-apps/6aae34eb8745becb3c92cdee/comment/6aafc41ac7b2c1ff0948ed9e"
---

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

Comment [Streaming vs JSON: Trade-offs in AI-Powered Apps](https://hashnode.com/posts/streaming-vs-json-trade-offs-in-ai-powered-apps/6aae34eb8745becb3c92cdee)

[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.
