npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ferrow/streaming-json-parser

v1.0.0

Published

Incremental JSON parser for LLM streams: feed(chunk) character state machine, path subscriptions (onValue('choices.0.delta', cb)), tolerant mode that completes truncated JSON, strict mode that rejects invalid input with position.

Readme

streaming-json-parser

Incremental JSON parser for TypeScript/JavaScript, built for the "parse JSON while the model is still typing" problem: feed it chunks as they arrive from an LLM stream, subscribe to specific paths to be notified as values appear and grow, and get a best-effort result at any point — even mid-stream, from truncated input. Zero runtime dependencies.

Why

Streaming an LLM's JSON output (tool calls, structured responses) means you have an incomplete JSON document at every point until the stream ends. This package parses it incrementally with a character state machine, lets you subscribe to a path ("choices.0.delta.content") and get called every time that value updates, and can hand back a best-effort completed object from a stream cut off mid-token.

Install

npm install streaming-json-parser

Quickstart

import { StreamingJsonParser } from "streaming-json-parser";

const parser = new StreamingJsonParser();

parser.onValue("choices.0.delta.content", (value) => {
  process.stdout.write(String(value)); // fires on every streamed character
});

for await (const chunk of llmStream) {
  parser.feed(chunk);
}

const { value, wasTruncated, complete } = parser.getResult();

API

new StreamingJsonParser(options?: ParserOptions)

ParserOptions = { strict?: boolean } (default false). In strict mode, malformed syntax throws StreamingJsonParseError (with .position) immediately from feed(). In tolerant mode (default), malformed syntax is skipped cleanly rather than thrown — the "tolerant" behavior most callers want is really getResult()'s truncation completion (below), not silent recovery from garbage.

feed(chunk: string): void

Appends chunk to the internal buffer and advances the parser as far as the buffered text allows.

onValue(path: string, callback: (value: unknown) => void): () => void

Subscribes to a dot-separated path (array indices as plain numbers, e.g. "choices.0.delta"). Fires on every update at that path: strings fire per character/escape sequence appended, objects/arrays fire on every child change, numbers/booleans/null fire once on completion. Returns an unsubscribe function.

getResult(): ParseResult

ParseResult = { value: unknown; wasTruncated: boolean; complete: boolean }. If a complete top-level JSON value has been received, returns it with wasTruncated: false, complete: true. Otherwise returns a best-effort snapshot — any in-progress string is closed as-is, any in-progress object/ array already reflects everything parsed so far — with wasTruncated: true, complete: false.

class StreamingJsonParseError extends Error

{ message: string; position: number } — thrown by feed() in strict mode only.

Limits

  • Numbers and true/false/null literals are only emitted via onValue once fully complete — only strings and objects/arrays stream incrementally. (An incomplete literal like "tr can't be guessed, so getResult() omits it rather than fabricating a value.)
  • Trailing commas are not explicitly rejected as an error, even in strict mode — this is a pragmatic streaming parser, not a full RFC 8259 conformance checker.
  • Assumes a single top-level JSON value per parser instance (the typical "one streamed object/array" case) — it does not parse a sequence of concatenated top-level values (JSON Lines) from one instance.
  • getResult()'s force-completion closes open strings/containers into a valid JS value; it does not hand back the text of a repaired JSON string (there's no getPartialText()), only the parsed value.

Part of the ferrow-toolkit collection · Sponsored by Ferrow