Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

A Partial JSON Parser You Can npm install

说明与用途

"fenced-json" 包可从 LLM 响应流中提取部分 JSON 对象,正确处理 Markdown 代码块、前缀和各种数据类型,并区分不完整和无效数据。

问题

Developers needed a reusable, dependency‑free parser to extract streaming JSON fields from LLM responses that may be wrapped in markdown fences or contain incomplete data.

结果

The new parser supports arbitrary JSON structures, correctly handles markdown fences and preambles, distinguishes incomplete from invalid data, and performs well enough for typical LLM responses (up to 4 KB) with per‑chunk costs under a frame.

工作流

  • 1. Install the package via npm.
  • 2. Create a PartialJson instance.
  • 3. Push incoming stream chunks to the instance.
  • 4. Access the partial value and check completion with isComplete().
  • 5. Render or process fields as they become complete.

证据

I only care about one field ("response"). The structure is known and flat. The value I need is always a string. I'm already handling the stream myself.

来源

The result's state is one of empty, partial, complete or invalid, and the rule the tests enforce is that every prefix of a valid document is one of the first three.

来源

Node 23.11 on an M-series laptop. A typical chat response with a few suggestions attached is under 4 KB. Even at 64 KB the per‑chunk cost is well under a frame.

来源

  • 记录日期: 2026-10-16T15:41:22.178Z