{"name":"is-my-json-valid","version":"2.12.2","description":"A JSONSchema validator that uses code generation to be extremely fast","main":"index.js","dependencies":{"generate-function":"^2.0.0","generate-object-property":"^1.1.0","jsonpointer":"2.0.0","xtend":"^4.0.0"},"devDependencies":{"tape":"^2.13.4"},"scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"https://github.com/mafintosh/is-my-json-valid"},"keywords":["json","schema","orderly","jsonschema"],"author":{"name":"Mathias Buus"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/is-my-json-valid/issues"},"homepage":"https://github.com/mafintosh/is-my-json-valid","readme":"# is-my-json-valid\n\nA [JSONSchema](http://json-schema.org/) validator that uses code generation\nto be extremely fast\n\n```\nnpm install is-my-json-valid\n```\n\nIt passes the entire JSONSchema v4 test suite except for `remoteRefs` and `maxLength`/`minLength` when using unicode surrogate pairs.\n\n[![build status](http://img.shields.io/travis/mafintosh/is-my-json-valid.svg?style=flat)](http://travis-ci.org/mafintosh/is-my-json-valid)\n\n## Usage\n\nSimply pass a schema to compile it\n\n``` js\nvar validator = require('is-my-json-valid')\n\nvar validate = validator({\n  required: true,\n  type: 'object',\n  properties: {\n    hello: {\n      required: true,\n      type: 'string'\n    }\n  }\n})\n\nconsole.log('should be valid', validate({hello: 'world'}))\nconsole.log('should not be valid', validate({}))\n\n// get the last list of errors by checking validate.errors\n// the following will print [{field: 'data.hello', message: 'is required'}]\nconsole.log(validate.errors)\n```\n\nYou can also pass the schema as a string\n\n``` js\nvar validate = validate('{\"type\": ... }')\n```\n\nOptionally you can use the require submodule to load a schema from `__dirname`\n\n``` js\nvar validator = require('is-my-json-valid/require')\nvar validate = validator('my-schema.json')\n```\n\n## Custom formats\n\nis-my-json-valid supports the formats specified in JSON schema v4 (such as date-time).\nIf you want to add your own custom formats pass them as the formats options to the validator\n\n``` js\nvar validate = validator({\n  type: 'string',\n  required: true,\n  format: 'only-a'\n}, {\n  formats: {\n    'only-a': /^a+$/\n  }\n})\n\nconsole.log(validate('aa')) // true\nconsole.log(validate('ab')) // false\n```\n\n## External schemas\n\nYou can pass in external schemas that you reference using the `$ref` attribute as the `schemas` option\n\n``` js\nvar ext = {\n  required: true,\n  type: 'string'\n}\n\nvar schema = {\n  $ref: '#ext' // references another schema called ext\n}\n\n// pass the external schemas as an option\nvar validate = validator(schema, {schemas: {ext: ext}})\n\nvalidate('hello') // returns true\nvalidate(42) // return false\n```\n\n## Filtering away additional properties\n\nis-my-json-valid supports filtering away properties not in the schema\n\n``` js\nvar filter = validator.filter({\n  required: true,\n  type: 'object',\n  properties: {\n    hello: {type: 'string', required: true}\n  },\n  additionalProperties: false\n})\n\nvar doc = {hello: 'world', notInSchema: true}\nconsole.log(filter(doc)) // {hello: 'world'}\n```\n\n## Verbose mode outputs the value on errors\n\nis-my-json-valid outputs the value causing an error when verbose is set to true\n\n``` js\nvar validate = validator({\n  required: true,\n  type: 'object',\n  properties: {\n    hello: {\n      required: true,\n      type: 'string'\n    }\n  }\n}, {\n  verbose: true\n})\n\nvalidate({hello: 100});\nconsole.log(validate.errors) // {field: 'data.hello', message: 'is the wrong type', value: 100}\n```\n\n## Greedy mode tries to validate as much as possible\n\nBy default is-my-json-valid bails on first validation error but when greedy is\nset to true it tries to validate as much as possible:\n\n``` js\nvar validate = validator({\n  type: 'object',\n  properties: {\n    x: {\n      type: 'number'\n    }\n  },\n  required: ['x', 'y']\n}, {\n  greedy: true\n});\n\nvalidate({x: 'string'});\nconsole.log(validate.errors) // [{field: 'data.y', message: 'is required'},\n                             //  {field: 'data.x', message: 'is the wrong type'}]\n```\n\n## Performance\n\nis-my-json-valid uses code generation to turn your JSON schema into basic javascript code that is easily optimizeable by v8.\n\nAt the time of writing, is-my-json-valid is the __fastest validator__ when running\n\n* [json-schema-benchmark](https://github.com/Muscula/json-schema-benchmark)\n* [cosmicreals.com benchmark](http://cosmicrealms.com/blog/2014/08/29/benchmark-of-node-dot-js-json-validation-modules-part-3/)\n* [jsck benchmark](https://github.com/pandastrike/jsck/issues/72#issuecomment-70992684)\n* [themis benchmark](https://cdn.rawgit.com/playlyfe/themis/master/benchmark/results.html)\n* [z-schema benchmark](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html)\n\nIf you know any other relevant benchmarks open a PR and I'll add them.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_id":"is-my-json-valid@2.12.2","_shasum":"0d65859318c846ce3a134402fd3fbc504272ccc9","_from":"https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.12.2.tgz","_resolved":"https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.12.2.tgz"}