MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Streaming JSON & NDJSON0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
12.1JSON.stringify Replacer & JSON.parse Reviver12.2Circular Reference Handling & Custom Serialization12.3JSON Schema Validation12.4Streaming JSON & NDJSON
HomeTutorialsJavaScript for AdvancedStreaming JSON & NDJSON
Critical Rendering Path & Reflow/Repaint

Streaming JSON & NDJSON

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

Standard JSON.parse() requires the entire response payload to be fully downloaded into memory before parsing begins. For huge datasets (e.g. 500MB log exports, live analytics feeds, financial order books), buffering the whole file in RAM causes browser tabs to crash with Out of Memory errors. Streaming JSON and NDJSON (Newline Delimited JSON) allow records to be processed item-by-item as chunks arrive over the wire.


1. What is NDJSON (Newline Delimited JSON)?

NDJSON (also known as JSON Lines or .jsonl) stores each JSON record on its own line separated by a newline character \n:

1{"id": 1, "event": "PAGE_VIEW", "url": "/home", "timestamp": 1710000000}
2{"id": 2, "event": "BUTTON_CLICK", "button": "signup", "timestamp": 1710000005}
3{"id": 3, "event": "FORM_SUBMIT", "form": "register", "timestamp": 1710000010}

Why NDJSON is Superior for Streaming:

  • No enclosing square brackets [ or trailing commas ,.
  • Each line can be passed directly to JSON.parse(line) immediately as it arrives!

2. Parsing NDJSON Streams with ReadableStream

1async function consumeNdjsonStream(url, onRecordReceived) {
2 const response = await fetch(url);
3 const reader = response.body.getReader();
4 const decoder = new TextDecoder('utf-8');
5 let leftoverBuffer = '';
6 
7 while (true) {
8 const { value, done } = await reader.read();
9 if (done) break;
10 
11 // Decode incoming binary chunk into string and append to leftover buffer
12 leftoverBuffer += decoder.decode(value, { stream: true });
13 
14 // Split buffer by newlines
15 const lines = leftoverBuffer.split('\n');
16 
17 // The last element may be incomplete! Keep it in the buffer for next chunk
18 leftoverBuffer = lines.pop();
19 
20 // Process all fully completed lines
21 for (const line of lines) {
22 const trimmed = line.trim();
23 if (trimmed) {
24 try {
25 const record = JSON.parse(trimmed);
26 onRecordReceived(record); // Stream to UI or store
27 } catch (e) {
28 console.error('Malformed NDJSON line:', trimmed);
29 }
30 }
31 }
32 }
33 
34 // Process any remaining tail in the buffer
35 if (leftoverBuffer.trim()) {
36 onRecordReceived(JSON.parse(leftoverBuffer.trim()));
37 }
38}

3. High-Performance Transform Streams

In modern browsers supporting TransformStream and TextDecoderStream, you can pipe streams with declarative backpressure:

1async function modernStream(url) {
2 const response = await fetch(url);
3
4 const stream = response.body
5 .pipeThrough(new TextDecoderStream())
6 .pipeThrough(new LineSplitterStream());
7 
8 for await (const line of stream) {
9 const json = JSON.parse(line);
10 renderRowToTable(json);
11 }
12}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the defining characteristic of NDJSON (Newline Delimited JSON)?
Question 2
Why does JSON.parse() fail when dealing with a 500MB continuous data stream?
Question 3
Why is leftoverBuffer = lines.pop() used when splitting streaming chunks by newline?
Question 4
Which standard browser API converts raw Uint8Array binary stream chunks into text strings while handling split multi-byte characters?
Question 5
What is the memory footprint of streaming 10 million NDJSON records compared to standard JSON.parse?
Next Lesson

Critical Rendering Path & Reflow/Repaint

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
JSON Schema ValidationCritical Rendering Path & Reflow/Repaint

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext