vstream-json-parser is a Node.js object-mode Transform stream designed for parsing chunks of UTF-8 text, typically newline-separated JSON objects, into plain JavaScript objects. Its current stable version is 1.0.1. The library differentiates itself by leveraging the `vstream` interface for warning management rather than emitting fatal `error` events for common operational issues like malformed JSON or `null` values. It processes transformations synchronously but throttles to one input per tick to maintain event loop liveness. Key features include its object-mode output, customizable `highWaterMark` (defaulting to 0 for low memory usage), and specific handling for `null` JSON values, which are ignored because Node.js streams cannot represent them without ending the stream. This package is particularly suited for processing large streams of structured log data or similar continuous JSON feeds where error recovery and liveness are critical. Given the last activity on GitHub (2015 copyright), the project appears to be in a maintenance or abandoned state.
npm install vstream-json-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a stream of newline-separated JSON objects, including malformed input and `null` values, and handling `vstream` warnings.
Implement an event listener for `stream.on('warning', handler)` to properly handle parsing issues and null value notifications.If `null` as a value is semantically important for your application, you must pre-process the stream to replace `null` with a placeholder (e.g., `{"_null_value": true}`) before piping it to `vstream-json-parser`.Always use `const JsonParserStream = require('vstream-json-parser');` to import the module.Do not explicitly set `objectMode: false` in constructor options, as it will be ignored. Ensure downstream streams are also in `objectMode` to handle the output.
Ensure your project is configured for CommonJS (`"type": "commonjs"` in `package.json` or omit `"type"`) or run with Node.js `--experimental-json-modules` flag if attempting to `import` a `.json` file directly (though not relevant for this parser).
Ensure all data is written to the `JsonParserStream` before calling `stream.end()`. If using `pipe`, the `end` event from the source stream will correctly call `end()` on the parser.
The parser expects UTF-8 text chunks. Ensure that upstream streams provide string or buffer data. If receiving objects, use a `Transform` stream to stringify them first, or ensure input is byte streams representing JSON.