🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

json-street

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-street

Simple and efficient streaming JSON processor.

latest
Source
npmnpm
Version
1.0.0-6
Version published
Maintainers
1
Created
Source

json-street

Simple and efficient streaming JSON processor.

npm install json-street;

Process JSON data incrementally without waiting for it to be fully received:

import * as jsonst from 'json-street;

const response = await fetch('https://api.example.com/data');
const stream = response.body.pipeThrough(new TextDecoderStream());

const items = [];

await jsonst.visit(stream, {
  items: item => items.push(item),
});

// {
//   "items": [
//     { "id": "1", "name": "foo", "metadata": { ... } },
//     { "id": "2", "name": "bar", "metadata": { ... } },
//     ...
//   ]
// }

Specify the expected type of the data to ensure the visitor is appropriately typed:

type Data = {
  items: {
    id: string;
    name: string;
    metadata: unknown;
  }[];
};

await jsonst.visit<Data>(stream, /* well-typed visitor */)

Use nested visitors to process complex schemas:

type User = {
  id: string;
  posts: {
    title: string;
    comments: {
      author: string;
      text: string;
    }[];
  }[];
};

const titles = [];
const comments = [];

await jsonst.visit<User>(stream, {
  posts: jsonst.array({
    title: t => titles.push(t),
    comments: jsonst.array(c => comments.push(c)),
  })
});

FAQs

Package last updated on 30 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts