The focus of i-json is on performance. The API is minimal and designed for speed but i-json can be used as a fast engine to power higher level JSON APIs (evented, streaming).
Installation
npm install i-json
API
var ijson = require('i-json');var parser = ijson.createParser();// update the parser with the next piece of JSON buffer.// This call will typically be issued from a 'data' event handlerparser.update(jsonChunk);// retrieve the resultvar obj = parser.result();
You can pass a Buffer or a string to parser.update. If you get your input data in a Buffer, you should pass it directly to parser.update; you should not convert it and pass it as a string.
You can also configure a callback which will be called during parsing:
callback receives the value and the path to the value. path is an array of object keys and array indexes that lead to the value.
The callback also allows you transform the value. If you return undefined from the callback, the parsed value will not be recorded into the final result. So you can implement a high level evented API by emitting events from the callback and returning undefined.
maxDepth lets you control the granularity of the callbacks. The callback will only be called when the depth of parsing is <= maxDepth. If you omit maxDepth the callback will be called on all the values.