Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Using the Streams API + TextDecoder for NDJSON const response = await fetch("https://api.example.com/stream"); const reader = response.body.getReader(); const decoder = new TextDecoder(); while (true) { const { done, value } = await reader.read(); if (done) break; const lines = decoder.decode(value).split(" "); for (const line of lines) { if (line) { const item = JSON.parse(line); // Newline-delimited JSON processItem(item); } } }
Result
Open