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

A Partial JSON Parser You Can npm install

Описание и применение

Пакет "fenced-json" позволяет извлекать частичные JSON‑объекты из потоков LLM‑ответов, корректно обрабатывая маркдаун‑фенсы, префиксы и различные типы данных, а также различая неполные и недопустимые данные.

Задача

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