Fjson
Bun

function

stream.consumers.json

function json(
stream: ReadableStream | AsyncIterable<any, any, any> | ReadableStream<any>
): Promise<unknown>;
import { json } from 'node:stream/consumers';
import { Readable } from 'node:stream';

const items = Array.from(
  {
    length: 100,
  },
  () => ({
    message: 'hello world from consumers!',
  }),
);

const readable = Readable.from(JSON.stringify(items));
const data = await json(readable);
console.log(`from readable: ${data.length}`);
// Prints: from readable: 100
@returns

Fulfills with the contents of the stream parsed as a UTF-8 encoded string that is then passed through JSON.parse().

Referenced types

interface ReadableStream<R = any>