Gathering detailed insights and metrics for @bahmutov/is-my-json-valid
Gathering detailed insights and metrics for @bahmutov/is-my-json-valid
Gathering detailed insights and metrics for @bahmutov/is-my-json-valid
Gathering detailed insights and metrics for @bahmutov/is-my-json-valid
A JSONSchema validator that uses code generation to be extremely fast
npm install @bahmutov/is-my-json-valid
Typescript
Module System
Node Version
NPM Version
JavaScript (77.29%)
TypeScript (22.71%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
968 Stars
236 Commits
112 Forks
26 Watchers
3 Branches
25 Contributors
Updated on Jun 07, 2025
Latest Version
2.17.3
Package Id
@bahmutov/is-my-json-valid@2.17.3
Unpacked Size
111.25 kB
Size
19.29 kB
File Count
46
NPM Version
3.10.10
Node Version
6.12.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Temporary fork from is-my-json-valid to have my fixes in
A JSONSchema validator that uses code generation to be extremely fast
npm install is-my-json-valid
It passes the entire JSONSchema v4 test suite except for remoteRefs
and maxLength
/minLength
when using unicode surrogate pairs.
Simply pass a schema to compile it
1var validator = require('is-my-json-valid') 2 3var validate = validator({ 4 required: true, 5 type: 'object', 6 properties: { 7 hello: { 8 required: true, 9 type: 'string' 10 } 11 } 12}) 13 14console.log('should be valid', validate({hello: 'world'})) 15console.log('should not be valid', validate({})) 16 17// get the last list of errors by checking validate.errors 18// the following will print [{field: 'data.hello', message: 'is required'}] 19console.log(validate.errors)
You can also pass the schema as a string
1var validate = validator('{"type": ... }')
Optionally you can use the require submodule to load a schema from __dirname
1var validator = require('is-my-json-valid/require') 2var validate = validator('my-schema.json')
is-my-json-valid supports the formats specified in JSON schema v4 (such as date-time). If you want to add your own custom formats pass them as the formats options to the validator
1var validate = validator({ 2 type: 'string', 3 required: true, 4 format: 'only-a' 5}, { 6 formats: { 7 'only-a': /^a+$/ 8 } 9}) 10 11console.log(validate('aa')) // true 12console.log(validate('ab')) // false
You can pass in external schemas that you reference using the $ref
attribute as the schemas
option
1var ext = { 2 required: true, 3 type: 'string' 4} 5 6var schema = { 7 $ref: '#ext' // references another schema called ext 8} 9 10// pass the external schemas as an option 11var validate = validator(schema, {schemas: {ext: ext}}) 12 13validate('hello') // returns true 14validate(42) // return false
is-my-json-valid supports filtering away properties not in the schema
1var filter = validator.filter({ 2 required: true, 3 type: 'object', 4 properties: { 5 hello: {type: 'string', required: true} 6 }, 7 additionalProperties: false 8}) 9 10var doc = {hello: 'world', notInSchema: true} 11console.log(filter(doc)) // {hello: 'world'}
When the verbose
options is set to true
, is-my-json-valid
also outputs:
value
: The data value that caused the errorschemaPath
: an array of keys indicating which sub-schema failed1var schema = { 2 required: true, 3 type: 'object', 4 properties: { 5 hello: { 6 required: true, 7 type: 'string' 8 } 9 } 10} 11var validate = validator(schema, { 12 verbose: true 13}) 14 15validate({hello: 100}); 16console.log(validate.errors) 17// [ { field: 'data.hello', 18// message: 'is the wrong type', 19// value: 100, 20// type: 'string', 21// schemaPath: [ 'properties', 'hello' ] } ]
Many popular libraries make it easy to retrieve the failing rule with the schemaPath
:
var schemaPath = validate.errors[0].schemaPath
var R = require('ramda')
console.log( 'All evaluate to the same thing: ', R.equals(
schema.properties.hello,
{ required: true, type: 'string' },
R.path(schemaPath, schema),
require('lodash').get(schema, schemaPath),
require('jsonpointer').get(schema, [""].concat(schemaPath))
))
// All evaluate to the same thing: true
By default is-my-json-valid bails on first validation error but when greedy is set to true it tries to validate as much as possible:
1var validate = validator({ 2 type: 'object', 3 properties: { 4 x: { 5 type: 'number' 6 } 7 }, 8 required: ['x', 'y'] 9}, { 10 greedy: true 11}); 12 13validate({x: 'string'}); 14console.log(validate.errors) // [{field: 'data.y', message: 'is required'}, 15 // {field: 'data.x', message: 'is the wrong type'}]
Here is a list of possible message
values for errors:
is required
is the wrong type
has additional items
must be FORMAT format
(FORMAT is the format
property from the schema)must be unique
must be an enum value
dependencies not set
has additional properties
referenced schema does not match
negative schema matches
pattern mismatch
no schemas match
no (or more than one) schemas match
has a remainder
has more properties than allowed
has less properties than allowed
has more items than allowed
has less items than allowed
has longer length than allowed
has less length than allowed
is less than minimum
is more than maximum
is-my-json-valid uses code generation to turn your JSON schema into basic javascript code that is easily optimizeable by v8.
At the time of writing, is-my-json-valid is the fastest validator when running
If you know any other relevant benchmarks open a PR and I'll add them.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/22 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More