invalid string length array.join javascript

157 Views Asked by At

I'm reading huge excel files on my frontend using SheetJS, and parsing them to JSON using XLSX.utils.sheet_to_json. But apparently, it exceeds V8's limit.

It worked fine when testing with small files, but when testing with slightly bigger files (around a million rows), I start getting the above error, I also tried to JSON.stringify each element at a time, but that still produces the same error. I'm uncertain about how to circumvent such an issue, I thought of converting the JSON to binary or gzipping it for POSTing to the server, but that still would require JSON.stringify on the object as far as I know.

The code I have so far for stringifying the JSON.

        const payloadEntries = Object.entries(payload).map(([key, value]) => {
          return `"${key}":[${value
            .map((el) => JSON.stringify(el))
            .join(",")}]`;
        });

The payload object looks like this


[
   {

      "A":"2023/23/10 1:19",
      "B":"3",
      "C":"1",
      "D":"3-1",
   }, 

 {

      "A":"2023/23/10 1:19",
      "B":"4",
      "C":"2",
      "D":"4-1",
   }, 

]

Edit: This uses normal JavaScript, not node.

0

There are 0 best solutions below