I realize that there are a ton of Node modules that provide an async API for parsing JSON, but many of them seem to read the entire file or stream into memory, construct a giant string, and then pass it to JSON.parse()
. This is what the second answer to "How to parse JSON using NodeJS?" suggests, and is exactly what the jsonfile module does.
Constructing a giant string is exactly what I want to avoid. I want an API like:
parseJsonFile(pathToJsonFile): Promise
where the Promise
that is returned resolves to the parsed JSON object. This implementation should use a constant amount of memory. I'm not interested in any sort of SAX-like thing that broadcasts events as various pieces are parsed: just the end result.
I think jsonparse may do what I want (it clearly includes logic for parsing JSON without using JSON.parse()
), but there is no simple example in the README.md
, and the one file in the examples directory seems overly complicated.