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 =// make an instanceconst parse =for var i = 0; i < 10; i++console// Check if the compiler found a matching schema.// If so it is using an optimised parser to parse the JSONconsole
API
const parse = jitson(opts)
Create a new JSON parser.
Options include
sampleInterval: 100 // sample the schema everytime we parse 100 objects
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