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

edge-json-stream

v1.0.0

Published

Hyper-efficient, zero-dependency JSON array streaming parser for browser and modern Edge runtimes like Cloudflare Workers and Vercel Edge.

Readme

edge-json-stream

Memory-safe JSON array streaming over the native Web Streams API for Edge runtimes.

npm version bundle size dependencies license

The Memory Problem at the Edge

Standard JSON parsing approaches—such as calling await response.json() or using JSON.parse()—require buffering the entire payload into RAM. In memory-constrained serverless environments (like Cloudflare Workers with a 128MB ceiling or Vercel Edge Functions), parsing arrays larger than 10MB-100MB+ can trigger catastrophic Out-Of-Memory (OOM) failures.

Furthermore, traditional JSON streaming libraries rely heavily on legacy Node.js stream APIs. These modules are unsupported by strict modern Edge environments that exclusively implement browser-native Web APIs.

edge-json-stream solves this by consuming a raw ReadableStream<Uint8Array> and parsing it chunk-by-chunk using a lightweight, character-by-character state machine. It streams objects to your logic as they arrive, ensuring memory overhead remains completely flat, regardless of stream length.

Core Features

  • Zero Runtime Dependencies — Restricts all packaging, building, and validation tools strictly to development environments.
  • Edge-Native Architecture — Relies exclusively on standard Web APIs (TextDecoder and ReadableStream), making it fully compatible with Cloudflare Workers, Vercel Edge, Bun, Deno, AWS Lambda, Node.js, and modern browsers.
  • Truncation & Buffer Resiliency — State machine seamlessly tracks and buffers partial strings, numbers, escaped quotes, and object braces across raw network packet boundaries.
  • Inferable TypeScript Generics — Fully-typed async generator yield types for end-to-end type safety and autocomplete.

Installation

# npm
npm install edge-json-stream

# pnpm
pnpm add edge-json-stream

# bun
bun add edge-json-stream

Quick Start

import { parseJsonArrayStream } from "edge-json-stream";

interface TransactionRecord {
  id: string;
  amount: number;
  status: "pending" | "completed" | "failed";
  timestamp: string;
}

async function processTransactions() {
  const response = await fetch("https://api.example.com/massive-transactions.json");
  
  if (!response.body) {
    throw new Error("API response is missing readable body stream");
  }

  // The stream is processed on-the-fly. Memory remains flat and minimal (< 100 KB).
  const stream = parseJsonArrayStream<TransactionRecord>(response.body);

  // Yields fully typed TransactionRecord objects one by one before the download completes.
  for await (const record of stream) {
    console.log(`Transaction ${record.id}: $${record.amount} is ${record.status}`);
  }
}

processTransactions().catch(console.error);

API Signature Matrix

| Function | Parameter | Returns | Execution Properties | | :--- | :--- | :--- | :--- | | parseJsonArrayStream<T = any> | stream: ReadableStream<Uint8Array> | AsyncGenerator<T, void, unknown> | Non-blocking, zero-dependency, character-by-character stream consumption. |

Advanced Resiliency Modes

The parser runs a single-pass state machine that maintains safety under standard streaming anomalies:

  • Chunk Cut-off Reassembly: If a network packet boundary cuts directly through a key name, a numeric value, or a string literal (e.g. {"amount": 12 ... 5.50}), the unparsed fragment is held in a local buffer and resolved correctly when the next chunk is appended.
  • String Escape Safety: The state machine tracks backslash escapes (e.g. \" or \\) within string literals, preventing literal quotes or nested brackets from corrupting the internal bracket counter.
  • Brace & Bracket Balancing: Tracks curly braces { and } balance outside of string literals to isolate root-level objects, while safely bypassing array wrappers ([ and ]), spacing, and trailing commas.

Performance Benchmark

| Metric | JSON.parse / response.json() | edge-json-stream | | :--- | :--- | :--- | | Bundle Footprint | 0 KB (Native) | < 1.5 KB (Gzipped, tree-shakable) | | Memory scaling | Linear (scales with payload size) ❌ | Flatline (constant <100 KB) ✅ | | Edge Runtime Compatible | Yes ✅ | Yes (100% standards-based) ✅ | | Streaming Output | No (blocking) ❌ | Yes (AsyncGenerator) ✅ |

License & Contributing

Licensed under the MIT License. Contributions are welcome—feel free to open an issue or submit a pull request on GitHub.