在 Node JS 中获取、操作和写入(响应)巨大 JSON 的最佳方式?

Best way to get, manipulate & write (response) huge JSON in Node JS?

我的预期任务:获取大量数据(1 GB 及更多大小)json 字符串,操作(进行一些格式化、解析 json、重组 json 数据)和将新格式化的 json 字符串写为响应。 处理这种情况的更好方法是什么?

从一些博客中我发现在流中存储大量数据是处理大量数据的有效方式,但是如何操作流数据?

我遇到的异常/错误:致命错误:CALL_AND_RETRY_2分配失败 - 进程内存不足 已中止(核心已转储)

输入JSON:

"docs": [ { "note_text": ["7657011|20MAR08|somehugedata|||7657012|20MAR09|somehugedata"], id:"c123" }, { "note_text": ["7657001|23MAR08|somehugedata|||7657002|21MAR08|somehugedata"], id:"c124" } ]

新格式 JSON:

"docs": [ { id:"c123", note_text : "somehugedata", date : "20MAR08" note_id : "7657011" }, { id:"c123", note_text : "somehugedata", date : "20MAR09" note_id : "7657012" }, { id:"c124", note_text : "somehugedata", date : "23MAR08" note_id : "7657001" }, { id:"c124", note_text : "somehugedata", date : "21MAR08" note_id : "7657002" } ]

看看JSONStream。有了它,您不必将整个巨大的 JSON blob 加载到内存中。您将一个接一个地处理源 JSON 中的对象,并在 JSONStream.parse().

中为它们指定正确的选择模式