How to Convert a JSON Stream to NDJSON easily

155 Views Asked by At

How can I convert a fetch response stream where the document being downloaded is JSON to a NDJSON stream? For example this code:

const response = await fetch(url);
    ndjsonStreamer = ndjsonStream(response.body).getReader();

works well for ndjson urls but fails for json urls. My goal is to try to convert the stream real-time from json to ndjson for the ndjsonStreamer to be able to parse it properly.

I thought about using fetch's pipeThrough method to pipe it to a Transform stream but that did not work too well.

Any ideas will be appreciated, thank you!

0

There are 0 best solutions below