incomplete-json-parser is a TypeScript module designed to robustly parse JSON strings that may be incomplete, chunked, or arriving in a streaming fashion. It provides an `IncompleteJsonParser` class and a static `parse` method to handle scenarios where standard `JSON.parse` would fail due to premature termination or fragmented input. The library, currently at version `1.1.5`, allows developers to incrementally feed JSON data via a `write` method and retrieve the most complete possible JavaScript object at any point using `getObjects()`. This makes it particularly suitable for processing real-time data streams, large file parsing, or handling responses from APIs that might send data in chunks or terminate early (e.g., during AI model responses). While a precise release cadence isn't defined, its versioning indicates active development and minor updates. A key differentiator is its fault tolerance, aiming to yield valid partial results even from highly fragmented inputs, unlike strict parsers that would immediately throw errors.
npm install incomplete-json-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a multi-chunk, incomplete JSON string into a JavaScript object incrementally, simulating a real-time stream. It also shows how to reset the parser for new data.
Always validate the completeness and correctness of the final parsed object if strict JSON adherence or schema validation is required. Consider additional validation layers on the output from `getObjects()`.
Ensure `parser.reset()` is invoked whenever a new, independent JSON stream or string begins using the same parser instance.
Always sanitize and validate the parsed JavaScript object against an expected schema or data type before using it in security-sensitive contexts or persistent storage. Consider libraries like Zod or Joi for schema validation.
For ESM, ensure `import { IncompleteJsonParser } from 'incomplete-json-parser';` is used. For CommonJS, use `const { IncompleteJsonParser } = require('incomplete-json-parser');`.Ensure `getObjects()` is called to retrieve the current state of the parsed object. If parsing multiple independent JSON strings, call `parser.reset()` before feeding new data to the same parser instance.
Review the source JSON stream for fundamental syntax errors beyond simple incompleteness. While the parser is robust, it cannot correct arbitrarily invalid JSON. Implement robust error handling or logging around the input source.
No dependency data recorded yet.