Accumulating Incomplete JSON Chunks from a ReadableStream

I'm looking to group chunks from a stream. I have a ReadableStream that is the streaming response body of an API service. It streams multiple JSON bodies (not an array), but each read() from the ReadableStream is an incomplete JSON string - so I need to accumulate until I receive a chunk that ends in a newline, at which point I can collect all chunks received so far into a string for JSON parsing. I need to then continue receiving chunks until the ReadableStream is closed. What would be the best operator for this?
Was this page helpful?