Bun Convert a Node.js Readable to JSON

Convert a Node.js Readable to JSON

jarle Updated

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/tree/main/skills/bun-guides-streams-node-readable-to-json commit b623985637

Frequently asked questions

npx skillmds@latest add jarle/bun-convert-a-node-js-readable-to-json