Giter Club home page Giter Club logo

is-my-json-valid's Introduction

is-my-json-valid

A JSONSchema/orderly validator that uses code generation to be extremely fast

npm install is-my-json-valid

build status

Usage

Simply pass a schema to compile it

var validator = require('is-my-json-valid')

var validate = validator({
  type: 'object',
  properties: {
    hello: {
      required: true,
      type: 'string'
    }
  }
})

console.log('should be valid', validate({hello: 'world'}))
console.log('should not be valid', validate({}))

// get the last list of errors by checking validate.errors
// the following will print [{field: 'data.hello', message: 'is required'}]
console.log(validate.errors)

You can also pass the schema as a string

var validate = validate('{"type": ... }')

Or pass a orderly schema

var validate = validate(
  'object {'+
  '  string name;'+
  '}*;'
)

Optionally you can use the require submodule to load a schema from __dirname

var validator = require('is-my-json-valid/require')
var validate = validator('my-schema.json')

// or load a orderly schema

var validate = validator('my-orderly-schema.schema')

Performance

This is module is fast

When running the cosmicrealms.com benchmark it yields the following results on my macbook air

is-my-json-valid v4 total time (632) and per document time: 0.00316
amanda v3 total time (27121) and per document time: 1.35605
jayschema v4 total time (99449) and per document time: 4.97245
joi v3 total time (11949) and per document time: 0.59745
json-gate v3 total time (1443) and per document time: 0.07215
json-schema v3 total time (1318) and per document time: 0.0659
JSV v3 total time (33495) and per document time: 1.67475
schema v2 total time (1309) and per document time: 0.06545
tv4 v4 total time (703) and per document time: 0.03515
z-schema v4 total time (3188) and per document time: 0.1594

As seen above is-my-json-valid is 2500x faster than the slowest and ~20x faster than the second fastest

License

MIT

is-my-json-valid's People

Contributors

mafintosh avatar watson avatar bobthekingofegypt avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.