jitson
Just-In-Time JSON.parse compiler
npm install jitson
Works by schema sampling the incoming data and if the schema is stable, it
will compile a fast parser for it using turbo-json-parse
Usage
const jitson = require('jitson')
const parse = jitson()
for (var i = 0; i < 10; i++) {
console.log(parse(JSON.stringify({hello: 'world', number: Math.random()})))
}
console.log(parse.schema)
API
const parse = jitson(opts)
Create a new JSON parser.
Options include
{
sampleInterval: 100
}
It keeps a small internal cache around of old schemas that is used to produce a better parser.
If the cache is empty it will sample right away as well.
Any additional options are forwarded to turbo-json-parse
when it triggers a parser compilation.
It works the best if you try to only pass data to it that has a schema so make
an instance for each of your http endpoints for example
const object = parse(src)
Similar to JSON.parse. Will schema sample the input once in a while
to check if it has a stable schema. If so it'll optimise the parser.
If you are parsing from Node.js buffers make sure to pass that as the src
instead of toString()ing it first as that will produce a faster parser
when compiling.
License
MIT