我正在尝试 json.stringify 一个 1 gb 的对象,以便我可以将它写入磁盘。我得到FATAL ERROR: JS Allocation failed - process out of memory
我该怎么做才能成功进行字符串化?
您可以通过手动位位字符串化:如果y是一个关键x,然后JSON.stringify(y) + ":" + JSON.stringify(x[y])给你一个段。
使用fs.appendFileSync,例如,你可以使用:
var output = "out.json";
fs.writeFileSync(output, "{");
var first = true;
for(var y in x) {
if(x.hasOwnProperty(y)) {
if(first) first = false;
else fs.appendFileSync(output, ",");
fs.appendFileSync(output, JSON.stringify(y) + ":" + JSON.stringify(x[y]))
}
}
fs.appendFileSync(output, "}");
Run Code Online (Sandbox Code Playgroud)
您还可以使用写入流
| 归档时间: |
|
| 查看次数: |
2617 次 |
| 最近记录: |