• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSON Schema Compiled checK

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}$"
        email:
          type: "string"
          format: "email"

console.log "valid document:", jsck.validate
  user:
    login: "matthew"
    email: "[email protected]"

{errors} = jsck.validate
  user:
    login: "matthew"
    email: "pandastrike.com"

console.log "invalid document:", errors

To use Draft 3 schemas:

validator = new JSCK.draft3(schema)

See these advanced usage examples for help working with multiple schemas.

Why JSCK?

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.

Coverage

Draft 4

JSCK passes all tests in the canonical JSON Schema Test Suite, except for these items:

  • 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.

For more information on the topic of the "id" attribute and scope manipulation, see this issue: json-schema/json-schema#77.

Contributing

To contribute, hack on it, or run the tests:

git clone [email protected]: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):

ajv : 1
jsen : 2.9
is-my-json-valid : 4.4
Themis (minimal) : 5.2
Themis : 5.3
JSCK : 34.2
z-schema : 48.3
tv4 : 54.4
jayschema : 2507.4

For the schema of medium complexity, our benchmarks produce this relative performance for the tested validators (lower is better):

ajv : 1
is-my-json-valid : 2.8
jsen : 3.0
Themis (minimal) : 11.1
Themis : 11.6
JSCK : 22.0
tv4 : 43.4
z-schema : 46.0
jayschema : 2319.4

For the schema of higher complexity, our benchmarks produce this relative performance for the tested validators (lower is better):

ajv : 1
is-my-json-valid : 1.23
jsen : 1.31
Themis (minimal) : 1.7
Themis : 1.8
JSCK : 4.8
z-schema : 17.2
tv4 : 27.0
jayschema : 1215.1

As the complexity of the schema increases, the performance benefits of the compilation model become more evident.

See this document for detailed results and information on running and creating benchmarks.

More Repositories

1

shred

A Node.js HTTP Client
CoffeeScript
248
star
2

bayzee

Text classification using Naive Bayes and Elasticsearch
Python
154
star
3

yaml-cli

A simple CLI for querying and updating YAML files
Shell
86
star
4

fairmont

Functional (and) reactive programming library for JavaScript.
CoffeeScript
50
star
5

orca

Distributed load testing framework
CoffeeScript
22
star
6

mutual

Task manager using Redis as a message transport
CoffeeScript
12
star
7

panda-panopticon

An AWS cloudwatch dashboard written in node.js using the AWS node.js SDK
JavaScript
11
star
8

p42

CLI that simplifies the use of Docker Machine, Swarm, and Compose
CoffeeScript
10
star
9

verse

A forward-looking Stylus-based CSS framework.
CSS
10
star
10

pirate

A simple storage interface with adapters for different storage systems
CoffeeScript
9
star
11

huxley

API and CLI for Docker Deployment
CoffeeScript
9
star
12

alexandria

A Web crawling framework in Node.js
CoffeeScript
8
star
13

haiku9

Static Site Publishing
CoffeeScript
8
star
14

ax

A simple Node.js logger.
CoffeeScript
7
star
15

ansible-cloudwatch-alarms

cloudwatch role for ansible galaxy
6
star
16

ark

Packages code for the browser as Node modules.
JavaScript
5
star
17

nice

Component-based (instead of template-based) views for CoffeeScript
CoffeeScript
5
star
18

panda-9000

A task and dependency tool based functional reactive programming
CoffeeScript
5
star
19

panda-cluster

Huxley - Cluster Management
CoffeeScript
4
star
20

testify

simple asynchronous testing in CoffeeScript using assertions of your choice
JavaScript
4
star
21

muppet

Python implementation of Mutual, although rather preliminary
Python
4
star
22

readis

Redis activity monitoring and data inspection
Ruby
4
star
23

panda-sky

Publish HTTP APIs to the Web just like static sites!
CoffeeScript
4
star
24

ansible-cloudwatch-metrics

cloudwatch metrics role for ansible galaxy
3
star
25

typely

A type-checking library in CoffeeScript.
CoffeeScript
3
star
26

panda-grammar

Recursive descent parser combinators in JavaScript
CoffeeScript
3
star
27

evie

Extends EventEmitter-like classes
CoffeeScript
3
star
28

starter

Generally helpful and reusable code
Ruby
3
star
29

base64-words

Convert base64 strings into human-friendly words
JavaScript
3
star
30

fate

Tools for running a service comprising multiple processes
Ruby
3
star
31

patchboard-rb

Ruby client for Patchboard APIs
Ruby
2
star
32

panda-glob

A globbing wrapper around minimatch optimized for repeated calls on large directories
CoffeeScript
2
star
33

key-forge

A simple key generation library for use with Node.
CoffeeScript
2
star
34

panda-hook

Huxley - Manage and Deploy Githook Scripts.
CoffeeScript
2
star
35

node-system

CoffeeScript
2
star
36

panda-kick

Sidekick-Server For Huxley Clusters - Grants Self-Sufficient Autonomy to Cluster Deployments
CoffeeScript
2
star
37

biscotti

Like Legos for building domain-specific languages (DSLs).
CoffeeScript
2
star
38

c50n

A very simple CSON parser / stringify
CoffeeScript
2
star
39

s3pub

Simple publishing module for use with S3.
CoffeeScript
2
star
40

madpanda

The Panda Strike bot.
CoffeeScript
2
star
41

canto

Value-added Redis library for Node.js
CoffeeScript
2
star
42

panda-lambda

A Set of Helpful AWS Lambda Functions
2
star
43

rephraser

Echoey HTTP server for developing and testing HTTP clients
CoffeeScript
2
star
44

panda-generics

Generic functions for JavaScript.
CoffeeScript
1
star
45

json-schema-tests

CoffeeScript
1
star
46

panda-serialize

Dead simple interface for serializing data formats.
CoffeeScript
1
star
47

maximumpanda

HTML
1
star
48

crossfire

A simple proxy that uses DNS SRV records to dynamically update its routing table.
CoffeeScript
1
star
49

panda-parchment

JavaScript helpers for use in functional programming.
CoffeeScript
1
star
50

panda-slides

HTML5 slides, the Panda way
CSS
1
star
51

docker-proxy

Single-minded reverse proxy that uses the Docker API to build its routing table.
CoffeeScript
1
star
52

coreos-reflector

"Hello World" introduction to CoreOS and Docker.
CoffeeScript
1
star
53

wavelet

A Shred-based API client for DigitalOcean
CoffeeScript
1
star
54

panda-vdom

VDOM helpers for writing direct VDOM-based templates
CoffeeScript
1
star
55

panda-river

Reactive programming in a functional style in JavaScript.
CoffeeScript
1
star
56

servitol

Static file server for testing web front ends. If file doesn't exist, it falls back to ./index.html or ../index.html
CoffeeScript
1
star