Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

825
Views
Cannot create a string longer than 0x1fffffe8 characters in JSON.parse?

I have JSON file which has json data of size 914MB. I loading the file with fs-extra and parsing it. But when i parse it get error as

cannot create a string longer than 0x1fffffe8 characters

Below is code

        const fs = require('fs-extra');
        const rawdata = fs.readFileSync('src/raw.json');
        const data = JSON.parse(rawdata);

I am running the project with npm and to run i have below command in package.json.

"scripts": {
   
    "start:dev": "cross-env NODE_OPTIONS='--max-old-space-size=4096' ts-node -r tsconfig-paths/register ./src --env=development",
  
  }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

0x1fffffe8 is exactly 512MB.

The many commenters are correct: you are bumping up against a system limit. I agree with @Pointy that it is mostly likely a Node string length limit. fs-extra has nothing to do with the limit

In any case, you're going to have to process that JSON in chunks.

Almost certainly your massive JSON data is an Array at the root level. So if you use a stream/SAX parser, you can process each element in that root array individually, or in batches, whichever makes sense.

ℹ️ You probably do not want a streaming parser that ONLY supports the JSON Streaming protocol, as that protocol is designed for a stream of multiple JSON objects concatenated in a stream. But from what I can tell you have one humungous monolithic JSON object, most likely an array at root as I mentioned above.

You have many parser options. To get you started, here are the ones with top usage on NPM:

  • https://github.com/creationix/jsonparse#readme

  • https://github.com/ndjson/ndjson.js

  • https://github.com/uhop/stream-json

  • https://www.npmjs.com/package/JSONStream (top, but archived)

  • https://gitlab.com/philbooth/bfj (#2, but also archived)

if performance is critical

If you know the source JSON is very regular in its formatting, e.g. every record in the root array is N lines long, the most efficient thing might be to read the raw lines via a buffered reader, grab every N lines (adjusting for the opening lines for the root array at the top), and JSON.parse those individually (after removing the comma separating root array entries. Just a raw idea. I've never done it!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!