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

jsonl-stream

v1.0.2

Published

A high-performance streaming parser for JSON Lines (JSONL) format in Node.js and TypeScript

Readme

jsonl-stream

npm version npm downloads license

A library for progressive parsing of JSON Lines (JSONL) — also known as NDJSON (Newline Delimited JSON) streams.

Specifically designed to process real-time data streams, such as AI model responses (LLM streaming like GPT/Gemini), massive log files, or any stream-based communication where network packets (chunks) arrive fragmented and incomplete over HTTP/HTTPS, WebSockets, gRPC, or local file system reads.


Key Features

  • Smart Parsing: Uses an internal character-by-character decoder that detects incomplete structures and buffers them until the next chunk arrives.
  • Complex Structures: Supports nested objects, complex arrays, strings with unicode escape characters (\uXXXX), booleans, null, and numbers in various notations (including scientific notation like -123.45e2).
  • Stream API Compatibility: Exposes a JsonlStream class extending the native Node.js Transform class, integrating seamlessly with pipes and streams in object mode (readableObjectMode: true). Ideal for HTTP requests and other streaming protocols.
  • Support for Diverse Line Endings: Works correctly with Windows (\r\n), Unix/modern macOS (\n), and classic macOS (\r) line endings, handling extra whitespaces, tabs, and indentation gracefully.
  • Robust End-Of-File (EOF) Handling: Allows explicitly indicating when the stream has ended (isEnd = true), forcing the parsing of remaining buffered numbers or primitive values.

Installation

npm install jsonl-stream

How to Use

The library is designed to be flexible. It works with the Node.js Stream API or by manually feeding chunks from persistent connections like WebSockets, gRPC, or Server-Sent Events (SSE).

1. Consuming data via HTTP Stream

Ideal for consuming APIs that send real-time data over HTTP/HTTPS.

Using fetch (Node.js 18+)

import { Readable } from "node:stream";
import { JsonlStream } from "jsonl-stream";

async function consumeFetchStream() {
  const response = await fetch("https://api.example.com/stream");

  // Converts fetch's ReadableStream to a Node.js Readable stream
  const readableStream = Readable.fromWeb(response.body as any);
  const jsonlParser = new JsonlStream();

  readableStream.pipe(jsonlParser);

  try {
    for await (const item of jsonlParser) {
      console.log("Token or object received via HTTP:", item);
    }
    console.log("HTTP Stream finished!");
  } catch (error) {
    console.error("Error consuming the stream:", error);
  }
}

consumeFetchStream();

Using the https module

import https from "node:https";
import { JsonlStream } from "jsonl-stream";

https.get("https://api.example.com/stream-jsonl", async (response) => {
  const jsonlParser = new JsonlStream();
  response.pipe(jsonlParser);

  try {
    for await (const item of jsonlParser) {
      console.log("JSON object received via HTTPS:", item);
    }
    console.log("HTTPS Stream successfully processed!");
  } catch (error) {
    console.error("Error in stream pipeline:", error);
  }
});

2. Reading Local Files via Stream

Ideal for processing extremely large JSONL files without exceeding memory limits.

import { createReadStream } from "node:fs";
import { JsonlStream } from "jsonl-stream";

async function processFile() {
  const fileStream = createReadStream("data.jsonl");
  const jsonlParser = new JsonlStream();

  fileStream.pipe(jsonlParser);

  try {
    for await (const item of jsonlParser) {
      console.log("Object read from file:", item);
    }
    console.log("Local file fully processed!");
  } catch (error) {
    console.error("Error processing file:", error);
  }
}

processFile();

🧪 Development and Testing

If you are developing or testing the library locally, use the following npm commands:

Build

Compiles TypeScript code, generating CJS, ESM bundles, and type definitions in the dist/ folder:

npm run build

Tests

Runs the full test suite using Vitest:

npm test

Issues & Feedback

If you encounter any bugs, have questions, or would like to request a new feature, please feel free to open an issue on GitHub. Your feedback and contributions are highly welcome!


License

This project is licensed under the MIT License. See the LICENSE file for details.