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

@portable/jsonl

v0.1.0

Published

Decode and encode JSON Lines (NDJSON) streams, in any JavaScript runtime.

Readme

@portable/jsonl

Decodes and encodes JSON Lines (.jsonl, also called NDJSON or newline-delimited JSON) streams. Runs in browsers, Cloudflare Workers, Node 24+, Bun, and Deno.

Replaces ndjson and the jsonl modules of stream-json.

npm install @portable/jsonl
import * as Jsonl from '@portable/jsonl';
import * as Streams from '@portable/streams';

const response = await fetch('https://example.com/events.ndjson');
const events = response.body!.pipeThrough(new Jsonl.DecoderStream());
for await (const event of Streams.toAsyncIterable(events)) {
  console.log(event);
}

DecoderStream is a TransformStream<Uint8Array | string, unknown> that parses each line with JSON.parse. Lines may end in LF or CRLF. Blank and whitespace-only lines are skipped, and a last line with no newline is decoded too. Byte chunks are decoded as UTF-8, so a multi-byte character split across chunks is decoded correctly.

EncoderStream is a TransformStream<unknown, Uint8Array> that writes each value as JSON.stringify(value) followed by \n, in UTF-8. A value that JSON.stringify can't encode (undefined, a function, a symbol, a BigInt, or a circular structure) fails the stream with a TypeError. Its output can be a Response body as it is:

const body = Streams.fromIterable(rows)
  .pipeThrough(new Jsonl.EncoderStream());
return new Response(body, { headers: { 'content-type': 'application/x-ndjson' } });

Options

DecoderStream takes invalid, maxLength, and signal. EncoderStream takes signal.

| Option | Default | Description | | --- | --- | --- | | invalid | 'error' | A line that isn't valid JSON: 'error' fails the stream with InvalidInputError, whose message gives the line number, and 'skip' drops the line. | | maxLength | Infinity | Longest line, in UTF-16 code units, line ending excluded. As soon as a line grows past the limit, the stream fails with Jsonl.MaxLengthError, which stores the limit in maxLength. Set it when the input comes from outside the program. | | signal | none | Aborting errors the stream with signal.reason and cancels the source piped into it. |

Why use this over ndjson and stream-json

ndjson is a pair of Node object streams. DecoderStream and EncoderStream are TransformStreams, so they read a fetch body and write a Response body in any JavaScript runtime, and the package has no dependencies outside @portable/*.

  • Decoding 20,000 rows ran about 1.1× faster than ndjson, and encoding them about 1.5× faster. stream-json's jsonl/Stringer encoded them about 1.3× faster than EncoderStream.
  • A null line is emitted as null. In ndjson a null line ends the stream, because Node object streams treat null as the end (ndjson #6).
  • EncoderStream ends every line with \n. ndjson uses os.EOL, so on Windows it writes \r\n.
  • A circular value fails the stream with a TypeError. ndjson writes "[Circular ~]" in its place, which changes the data.
  • A whitespace-only line is skipped, where ndjson reports it as invalid.
  • stream-json's jsonl/Parser emits { key, value } objects, and DecoderStream emits each value on its own.
  • stream-json's jsonl/Parser can replace a bad line with another value or pass its raw text on, and DecoderStream can't. To do that, split with Lines.DecoderStream from @portable/lines and call JSON.parse yourself.

Operations per second from pnpm bench, higher is better, in Node 24.22.0, on Intel(R) Xeon(R) Processor @ 2.10GHz (4 cores). Each benchmark lists only the libraries that can do the same work, fastest first. The relative speed compares each library with @portable/jsonl, and the bars are scaled to the fastest library.

| Library | Version | Minified and gzipped | Runtime dependencies | Node built-ins | TypeScript types | | --- | --- | ---: | ---: | --- | --- | | @portable/jsonl | – | 1.2 kB | 3 | none | included | | ndjson | 2.0.0 | 13 kB | 9 | buffer, events, os, string_decoder, util | @types/ndjson | | stream-json | 3.7.0 | 3.5 kB | 1 | stream, string_decoder | included | | JSON.parse or JSON.stringify | – | built in | – | none | – |

Sizes cover the imports in the usage example, or the equivalent imports of each library, bundled for the browser by scripts/bundle-size.ts. Runtime dependencies count every package installed with the published package. A library that uses Node built-ins needs polyfills in a browser and the nodejs_compat flag in Cloudflare Workers.