Skip to content

fix error-maximum-call-stack-size-exceeded for json object greater than 100,00 nodes #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,24 @@ async function convert(data, header = true, allColumns = false) {
csvInput.push(columnNames);
}

// Add all other rows:
csvInput.push(
...data.map(row => columnNames.map(column => row[column])),
);
if (data.length < 100000)
{
// Add all other rows:
csvInput.push(
...data.map(row => columnNames.map(column => row[column])),
);
}
else{
// manually load to array to avoid stack heap error on data length > 100,000 rows
// https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
for (const row in data) {
let rowData = [];
columnNames.forEach(column => {
rowData.push(data[row][column])
});
csvInput.push(rowData);
}
}

return await csv.stringify(csvInput);
}
Expand Down