jsonparse is a pure JavaScript library providing a streaming JSON parser for Node.js environments. Currently at version 1.3.1, this package allows developers to process large JSON inputs incrementally, rather than loading the entire structure into memory like the built-in `JSON.parse` method. This streaming capability is its primary differentiator, enabling more memory-efficient handling of vast datasets or continuous data feeds. However, the package has seen no updates since 2012, indicating it is no longer actively maintained. Its release cadence is effectively nonexistent, and it targets very old Node.js versions (0.2.0+). Developers should be aware of its age when considering it for modern applications.
npm install jsonparseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `jsonparse` to incrementally parse a large JSON string by handling individual objects or values as they are identified in the stream. It shows how to initialize the parser, handle `onValue` events for specific paths (like array items or top-level objects), and manage parsing errors and completion.
Consider modern, actively maintained streaming JSON parsers like `JSONStream` or `@streamparser/json`, which offer better performance, security, and ESM compatibility. If full document parsing is sufficient, `JSON.parse` is native and highly optimized.
Ensure your project uses CommonJS or use dynamic `import()` if you must use it within an ESM context (which is generally discouraged for unmaintained libraries). It's best to refactor to a modern ESM-compatible streaming parser.
Benchmark against native `JSON.parse` (if the full string fits in memory) or other performant streaming libraries to assess suitability for your specific performance requirements. Libraries like `@streamparser/json` are designed for speed while remaining pure JS.
Thoroughly test `onValue` logic, especially with complex or malformed JSON. Pay attention to `this.stack` to understand the current parsing depth and path. Consider using a JSONPath-like approach if you only need specific parts of the JSON.
Change your import statement to `const JSONParse = require('jsonparse');` to correctly load the CommonJS module.Inspect the input JSON for syntax errors (e.g., missing commas, unquoted keys, incorrect primitive values). Ensure that the data being passed to `parser.write()` forms valid JSON when concatenated, or that errors are handled via `parser.onError`.
No dependency data recorded yet.