<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb" -->

---
title: Handling Large JSON Files in Node.js | daily.dev
description: Loading large JSON files with JSON.parse() can exhaust memory and crash Node.js processes. The post covers practical strategies for handling...
canonical: https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Handling Large JSON Files in Node.js | daily.dev
og:description: Loading large JSON files with JSON.parse() can exhaust memory and crash Node.js processes. The post covers practical strategies for handling...
og:url: https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb
og:image: https://api.daily.dev/og/posts/tmR5761hB.png
og:image:alt: Handling Large JSON Files in Node.js
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling Large JSON Files in Node.js

**[Medium](https://daily.dev/sources/medium_js)** · 5 min read · 2 upvotes · 0 comments

## Summary

Loading large JSON files with JSON.parse() can exhaust memory and crash Node.js processes. The post covers practical strategies for handling multi-hundred-megabyte JSON files: using readable/writable streams, adopting NDJSON format for line-by-line parsing, processing records incrementally instead of buffering results, avoiding unnecessary object copies, measuring heap usage with process.memoryUsage(), compressing files with zlib, and writing output as a stream. It also notes when JSON.parse() is still the right choice for small files.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@jsdevspace/handling-large-json-files-in-node-js-ea3a3be0a473>

## Questions this post answers

### Why does JSON.parse() run out of memory on a large JSON file in Node.js?

JSON.parse() requires the entire file to be read into memory as a string and then allocated again as a parsed JavaScript object, so a 2GB file can temporarily require several gigabytes of RAM before any processing happens. This makes the standard read-then-parse pattern unsuitable for very large files and pushes memory usage and event loop responsiveness into problematic territory.

_Track patterns like this for JSON and Node.js performance work on daily.dev._

### Why can't I parse a large JSON file chunk by chunk with fs.createReadStream and JSON.parse()?

JSON.parse() expects a complete, well-formed document, but a stream delivers arbitrary chunks that may split in the middle of an object or array, so ordinary JSON.parse() fails on partial data. Parsing JSON incrementally as it streams in requires a dedicated streaming JSON parser rather than the built-in parser.

_Developers streaming JSON data in Node.js can follow deeper guides like this on daily.dev._

### What is NDJSON and why is it better than a JSON array for large datasets?

NDJSON stores each object on its own line instead of wrapping everything in one giant array, so every line is independently valid JSON that can be parsed one at a time with a simple loop like JSON.parse(line) inside a for-await loop. This avoids the need for a dedicated streaming parser and is widely used for logs, analytics pipelines, and large exports.

_Choosing between JSON and NDJSON for large exports is easier with resources like this on daily.dev._

## Similar posts on daily.dev

- [How to Stream Large Files with Node.js Streams in NestJS](https://daily.dev/posts/how-to-stream-large-files-with-node-js-streams-in-nestjs-qtlmlgloq) · Telerik · 3 upvotes · 0 comments
- [JSON Parsing for Large Payloads: Balancing Speed, Memory, and Scalability](https://daily.dev/posts/json-parsing-for-large-payloads-balancing-speed-memory-and-scalability-pw8ccar6b) · Towards Data Science · 1 upvotes · 0 comments
- [Streaming JSON in just 200 lines of JavaScript – Frontend Masters Blog](https://daily.dev/posts/streaming-json-in-just-200-lines-of-javascript-frontend-masters-blog-yyfhp6ohw) · Frontend Masters · 0 upvotes · 0 comments
- [How I Handled 5GB\+ File Uploads Without Breaking My Node.js Server](https://daily.dev/posts/how-i-handled-5gb-file-uploads-without-breaking-my-node-js-server-opkdprsgx) · Dev Genius · 18 upvotes · 3 comments

---

Tags: [#nodejs](https://daily.dev/tags/nodejs)

[View this post on daily.dev](https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Handling Large JSON Files in Node.js","url":"https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb"},"datePublished":"2026-07-17T18:19:45.240Z","dateModified":"2026-09-14T08:19:26.345Z","description":"Loading large JSON files with JSON.parse() can exhaust memory and crash Node.js processes. The post covers practical strategies for handling...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5dfbfdb4be460395ddcdfb3f89bb7470?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5dfbfdb4be460395ddcdfb3f89bb7470?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"nodejs","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Handling Large JSON Files in Node.js"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/handling-large-json-files-in-node-js-tmr5761hb#faq","mainEntity":[{"@type":"Question","name":"Why does JSON.parse() run out of memory on a large JSON file in Node.js?","acceptedAnswer":{"@type":"Answer","text":"JSON.parse() requires the entire file to be read into memory as a string and then allocated again as a parsed JavaScript object, so a 2GB file can temporarily require several gigabytes of RAM before any processing happens. This makes the standard read-then-parse pattern unsuitable for very large files and pushes memory usage and event loop responsiveness into problematic territory. Track patterns like this for JSON and Node.js performance work on daily.dev."}},{"@type":"Question","name":"Why can't I parse a large JSON file chunk by chunk with fs.createReadStream and JSON.parse()?","acceptedAnswer":{"@type":"Answer","text":"JSON.parse() expects a complete, well-formed document, but a stream delivers arbitrary chunks that may split in the middle of an object or array, so ordinary JSON.parse() fails on partial data. Parsing JSON incrementally as it streams in requires a dedicated streaming JSON parser rather than the built-in parser. Developers streaming JSON data in Node.js can follow deeper guides like this on daily.dev."}},{"@type":"Question","name":"What is NDJSON and why is it better than a JSON array for large datasets?","acceptedAnswer":{"@type":"Answer","text":"NDJSON stores each object on its own line instead of wrapping everything in one giant array, so every line is independently valid JSON that can be parsed one at a time with a simple loop like JSON.parse(line) inside a for-await loop. This avoids the need for a dedicated streaming parser and is widely used for logs, analytics pipelines, and large exports. Choosing between JSON and NDJSON for large exports is easier with resources like this on daily.dev."}}]}
```

