15 lines
567 B
Plaintext
15 lines
567 B
Plaintext
---
|
|
title: Convert a Node.js Readable to JSON
|
|
sidebarTitle: Readable to JSON
|
|
mode: center
|
|
---
|
|
|
|
To convert a Node.js `Readable` stream to a JSON object in Bun, create a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) with the stream as the body, then call [`response.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json).
|
|
|
|
```ts
|
|
import { Readable } from "stream";
|
|
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
|
|
const json = await new Response(stream).json();
|
|
console.log(json); // { hello: "world" }
|
|
```
|