Files
bun.sh/docs/guides/streams/node-readable-to-json.md
2024-04-18 22:46:43 -07:00

578 B

name
name
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" }