nano-json-stream-parser

0.1.2 · abandoned · verified Sun Apr 19

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

Install

Imports

Quickstart

Demonstrates how to initialize the streaming JSON parser and feed it chunks of a JSON string, showing how complete JSON objects are emitted via the provided callback. It also illustrates its behavior with fragmented and escaped JSON.

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" ]');

view raw JSON →