nano-json-stream-parser
This library (`nano-json-stream-parser`) provides a lightweight, pure JavaScript streamed JSON parser, weighing approximately 750 bytes (gzipped). Currently at version 0.1.2, it aims to offer functionality similar to larger alternatives like Oboe.js, achieving an 85% size reduction in bundle size, which is critical for highly optimized web applications or environments with strict resource constraints. The parsing mechanism involves feeding chunks of a JSON string to a function, which then invokes a callback whenever a complete JSON entity (object or array) has been fully parsed. However, a significant caveat is that the project explicitly states it lacks comprehensive tests and may contain buggy edge-cases, making it potentially unsuitable for mission-critical production environments without thorough internal validation. Its development appears to be inactive, with the last commit several years ago, indicating it is not actively maintained, nor does it have a clear release cadence, suggesting it's largely abandoned. Developers should be aware of these limitations when considering its use for new projects.
Warnings
- gotcha The library explicitly states, 'This library has no tests yet and could contain buggy edge-cases.' This means it is not production-ready and may produce incorrect results or unexpected behavior in various scenarios.
- breaking The project appears to be abandoned with no recent commits or updates (last commit several years ago). This indicates a lack of ongoing maintenance, security patches, or support for new JavaScript features and environments.
- gotcha The parser is designed to ignore invalid JSON fragments or malformed syntax without throwing an explicit error, as indicated by the example `parse("[::invalid_json_is_ignored::]")`. While this prevents crashes, it can lead to silent data loss or incomplete parsing if not explicitly handled by the consumer.
Install
-
npm install nano-json-stream-parser -
yarn add nano-json-stream-parser -
pnpm add nano-json-stream-parser
Imports
- default
import parse from 'nano-json-stream-parser';
const parse = require('nano-json-stream-parser'); - parse
import { parse } from 'nano-json-stream-parser';(No named export for the main functionality)
Quickstart
const njsp = require("nano-json-stream-parser");
// Callback is called when there is a complete JSON
const parse = njsp((json) => {
console.log('Parsed JSON:', JSON.stringify(json));
});
console.log('--- Parsing [1,2,3,4] ---');
parse('[1,2,3,4]');
console.log('--- Parsing [1,2,3,4] in chunks ---');
parse('[1,2');
parse(',3,4]');
console.log('--- Parsing object in chunks ---');
parse('{"pos": {"x":');
parse('1.70, "y": 2.');
parse('49, "z": 2e3}}');
console.log('--- Parsing string with escapes ---');
parse('[ "aaaa\"abcd\\u0123\\\\aa\/aa" ]');