Bun Convert a Node.js Readable to JSON

Convert a Node.js Readable to JSON

jarle Updated 9 repo stars

File contents

Convert a Node.js Readable to JSON

To convert a Node.js Readable stream to a JSON object in Bun, you can create a new Response object with the stream as the body, then use response.json() to read the stream into a JSON object.

import { Readable } from "stream";
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
const json = await new Response(stream).json();
console.log(json); // { hello: "world" }

jarle/bun-skills commit b623985637

Frequently asked questions

npx get-skill add jarle/bun-convert-a-node-js-readable-to-json