1.0.9 • Published 8 years ago

chunk2json v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

NPM version Build Status downloads per month Coverage Status

chunk2json


JSON parser that extracts JSON objects out of a byte stream without the use of delimeters.
Ideal for extracting JSON objects out of an incoming TCP socket byte stream.

Install

Install with npm:

$ npm install chunk2json

Use

const ChunkParser = require("chunk2json");
const parser = new ChunkParser();

parser.on("json", (jsonBuff) => {
    const result = JSON.parse(jsonBuff);
    console.log(result); // Prints the expected array
});

parser.consume(new Buffer('[{"name": "Frank Castle"'));
parser.consume(new Buffer(',"kills": true,'));
parser.consume(new Buffer('"line": "One batch, two batch, penny and dime"}'));
parser.consume(new Buffer(',{"name": "Bruce Wayne"'));
parser.consume(new Buffer(',"kills": false,'));
parser.consume(new Buffer('"line": "I am the goddamn Batman"}]'));

The parser consumes buffers which can contain partial and/or complete JSON chunks. When a complete JSON object is identified the on("json") event callback is invoked with the corresponding JSON object(in buffer form).

Test

Run the tests

$ npm test 

License

Copyright (c) 2016 Ioannis Tzanellis Released under the MIT license

1.0.9

8 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago