<script type="module">
import jsck from 'https://cdn.skypack.dev/jsck';
</script>
README
JSON Schema Compiled checK
JSCK is one of the fastest JSON Schema validators for Node.js.
It supports JSON Schema drafts
3 and
4,
with a few caveats (see the Coverage section below).
Installation and Usage
Install with NPM:
npm install --save jsck
Require:
JSCK = require "jsck"
JSCK can create validators from multiple schemas, but this requires that
each schema be identified with a URI in a top-level "id" field. In many
cases, only a single schema is needed, and there is no need to uniquely
identify the schema. This is the easiest way to use JSCK, as it is a
common pattern.
# Construct a validator for a schema lacking an "id" declaration
jsck = new JSCK.draft4
type: "object"
properties:
user:
type: "object"
required: ["login"]
properties:
login:
type: "string"
pattern: "^[\\w\\d_]{3,32}
JSCK is faster than most other JavaScript/CoffeeScript libraries
for validating JSON Schemas because it "compiles" the schemas. That is, JSCK
generates the tree of functions needed to validate a particular schema when you
construct a validator. The schema is thus traversed only during preparation, and
most of the work of interpreting the schema is done at this time, rather than
for every document submitted for validation. This minimizes the work required
during validation, which leads to substantial performance improvements over
non-compiling validators.
use of maxLength and minLength with Unicode surrogate pairs.
refRemote (this is an essential feature we do plan to support)
ref
remote ref, containing refs itself
uniqueItems
optional/zeroTerminatedFloats
Draft 3
Currently passing the canonical test suite for draft3 except for
these items:
refRemote
ref
remote ref, containing refs itself
uniqueItems
optional/zeroTerminatedFloats
Managing resolution scope with the "id" attribute
JSCK does not support the full range of scope manipulations suggested by JSON
Schema drafts 3 and 4. Scope manipulation is a controversial topic, and with
JSCK we have chosen to play it safe, supporting "id" declarations only in cases
that will (probably) not lead to any ambiguity. Specifically, JSCK uses "id"
declarations only in these cases:
at the top level of a schema, to provide a namespace for schemas not loaded from URIs.
non-JSON-pointer fragments ("id": "#user"), which serve merely as aliases for specific subschemas, and are thus convenient and unambiguous.
git clone git@github.com:pandastrike/jsck.git
cd jsck
coffee tasks/update
npm install
Tests
JSCK uses the official JSON Schema Test Suite as well as some
custom tests. To run all tests for all versions:
coffee test
See this document for more information on working with JSCK tests.
Benchmarks
JSCK has fairly comprehensive benchmarks which show it to be one of the very
fastest JSON Schema validators available for Node.js. Pull requests welcome, of
course.
Because performance varies (at very least) based on the complexity
of the schema being validated, we run benchmarks against several different
schemas, ranging from quite simple to moderately complex.
For JSON Schema Draft4, we run benchmarks against JSCK, tv4, jayschema,
z-schema, and other validators. On the
trivial schema,
our benchmarks produce this relative performance for these validators
(lower is better):