Registry / serialization / jitson

jitson

JSON →
library1.0.0jsnpmunverified

Just-In-Time JSON.parse compiler that optimizes parsing by schema sampling. Version 1.0.0 is stable. It samples incoming JSON data and if a stable schema is detected, compiles a fast parser using turbo-json-parse. Differentiators: JIT compilation based on runtime schema analysis, supports Node.js buffers for faster parsing. Maintained by mafintosh. Release cadence is low; no recent updates.

npm install jitson
INSTALL
IMPORT
SIG · JITSON
J
jitson
serializationjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (jitson function)
import jitson from 'jitson'
const jitson = require('jitson')
Package is ESM-only; use ESM import or dynamic import() in CommonJS.
jitson constructor
const parse = jitson()
const parse = new jitson()
jitson is a factory function, not a class. Do not use 'new'.
parse function
const obj = parse(jsonString)
parse(JSON.parse(jsonString))
parse expects a JSON string or Buffer, not a parsed object.
parse.schema
const schema = parse.schema
After parsing, check parse.schema to see if an optimized parser is being used (null if not).

Demonstrates JIT compilation: after several parses with a stable schema, parse.schema becomes non-null.

import jitson from 'jitson'; const parse = jitson({ sampleInterval: 10 }); for (let i = 0; i < 10; i++) { const obj = parse(JSON.stringify({ hello: 'world', number: Math.random() })); console.log(obj); } console.log('Optimized schema:', parse.schema);
Debug
Known issues
gotchajitson is not a class; do not use 'new'.
fix
Call jitson() directly (const parse = jitson()).
affects: >=1.0.0
gotchaThe parse function expects a string or Buffer, not a parsed object.
fix
Pass JSON.stringify output to parse, not JSON.parse output.
affects: >=1.0.0
gotchaThe underlying turbo-json-parse may fail for very complex or nested schemas.
fix
Fall back to JSON.parse manually if jitson throws.
affects: >=1.0.0
gotchaSchema detection works best when each endpoint uses a separate jitson instance.
fix
Create one jitson instance per API endpoint or data source.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: jitson is not a constructor
Using 'new jitson()' instead of calling jitson() as a function.
fix
const parse = jitson(); // No 'new' keyword
TypeError: parse.schema is not an object
Accessing parse.schema before any parsing has been done.
fix
Call parse() at least once before checking parse.schema. After schema stabilization it will be an object.
Error: Unable to compile parser - schema too complex
The JSON schema is too complex for turbo-json-parse to compile.
fix
Simplify the JSON data structure or fall back to JSON.parse.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
turbo-json-parserequiredUses turbo-json-parse to compile optimized parsers when schema is stable.
Agent activity
6 hits · last 30 days
node
6
Resources
jitson — npm install jitson · libregistry