{"_id":"@bahmutov/is-my-json-valid","_rev":"2-e67e06689b05253403b0164f0f7f3700","name":"@bahmutov/is-my-json-valid","dist-tags":{"latest":"2.17.3"},"versions":{"2.17.3":{"name":"@bahmutov/is-my-json-valid","version":"2.17.3","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","is-my-ip-valid":"^1.0.0","jsonpointer":"^4.0.0","xtend":"^4.0.0"},"devDependencies":{"safe-regex":"^1.1.0","tape":"^2.13.4"},"scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/is-my-json-valid.git"},"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","gitHead":"0a24a852487a73daa7c993ad07633899ddcfee51","_id":"@bahmutov/is-my-json-valid@2.17.3","_shasum":"955e8e9767db913e55c4c3f541dcfd2a30e160c4","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.12.2","_npmUser":{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"},"dist":{"shasum":"955e8e9767db913e55c4c3f541dcfd2a30e160c4","tarball":"https://registry.npmjs.org/@bahmutov/is-my-json-valid/-/is-my-json-valid-2.17.3.tgz","fileCount":46,"unpackedSize":113917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa536KCRA9TVsSAnZWagAAFr8P/iDZ7QS7kgjZKRU2tIKO\nuwdWBL5qlORO8ysNmWIEJVNupRdkhBMRY1pd2T3ZZkDt4gONQIHk3Ju2BCRP\nz7VMf+SVYyTsrqaift10aqkNdsGdl2h8GYlBOFNBaoM9olpMQ7GOduxGhLBU\nb00fU2qZsjW0nEPJBY3u6kGkEHIXkt0V3yesmJhMaUW0Kwvac07UhGo/X2sZ\nCUXCpuAiayUAdlcOs7FtUUE8UxPdx3vK0j/6QgjrdeJQg34KkdNM130H8eOQ\n+j3MYrhRbVKDjBoJVzDnO97xFvdo78yVtkSDYITN2X0LwtrCMgq3cRzTwJGN\ncrVy+KevsuAC/65TN1IdedsFiWn48A/COcfCKNNk1nSm0QJkwJ4G8231qJea\nXQ8O5iwT98AxOYiqhr3cSTJHhogOWrpfJ5VJFNckDCr8ifLDLRWYBAUAIdqB\nFfdj+Udlq1KrynyerRlfBR3aO54yroTEVTWHsXZJ3m2Nx78qCE8+0jkqCEfl\nA0vebQRsUNJ90HOncYEF+K3Zobtg/XimK1pKRjvR8Arti3RmOfpHd+KjJyIN\ndvhBGAGnsTlJ9C5vdHjFcX99Ai3c7TGTeMZnI4uzmHWn3BDClY0cukYqpOsY\nL9HtfFxsOxDJw/70AOEEW/98EhDhtJrVYqoyEYL+bg1ncrCk6/pStau394S/\nGgQb\r\n=YGxa\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-NSxJsPQKXE2CGu2U7V9hFQYZNYpHXv88hd9cH7pVWOdIqcvgeR/MeaX16AoigWiRlYjEkx2v6IgKZcmmBFWDfQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXR+ex0I1eXC6wM4dUc1BlbsATXFbApTWlUx0pm2K5ZAIged2pZqRSV5tziyZWUDPfSl0tQhGVlZxS0Oj33F0ClC0="}]},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/is-my-json-valid_2.17.3_1525120649293_0.23672706408550903"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-30T20:37:29.233Z","2.17.3":"2018-04-30T20:37:29.379Z","modified":"2022-06-12T15:01:56.660Z"},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"description":"A JSONSchema validator that uses code generation to be extremely fast","homepage":"https://github.com/mafintosh/is-my-json-valid","keywords":["json","schema","orderly","jsonschema"],"repository":{"type":"git","url":"git+https://github.com/mafintosh/is-my-json-valid.git"},"author":{"name":"Mathias Buus"},"bugs":{"url":"https://github.com/mafintosh/is-my-json-valid/issues"},"license":"MIT","readme":"# is-my-json-valid\n\nTemporary fork from [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid) to have my fixes in\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 = validator('{\"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 shows more information about the source of the error\n\nWhen the `verbose` options is set to `true`, `is-my-json-valid` also outputs:\n\n- `value`: The data value that caused the error\n- `schemaPath`: an array of keys indicating which sub-schema failed\n\n``` js\nvar schema = {\n  required: true,\n  type: 'object',\n  properties: {\n    hello: {\n      required: true,\n      type: 'string'\n    }\n  }\n}\nvar validate = validator(schema, {\n  verbose: true\n})\n\nvalidate({hello: 100});\nconsole.log(validate.errors)\n// [ { field: 'data.hello',\n//     message: 'is the wrong type',\n//     value: 100,\n//     type: 'string',\n//     schemaPath: [ 'properties', 'hello' ] } ]\n```\n\nMany popular libraries make it easy to retrieve the failing rule with the `schemaPath`:\n```\nvar schemaPath = validate.errors[0].schemaPath\nvar R = require('ramda')\n\nconsole.log( 'All evaluate to the same thing: ', R.equals(\n  schema.properties.hello,\n  { required: true, type: 'string' },\n  R.path(schemaPath, schema),\n  require('lodash').get(schema, schemaPath),\n  require('jsonpointer').get(schema, [\"\"].concat(schemaPath))\n))\n// All evaluate to the same thing: true\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## Error messages\n\nHere is a list of possible `message` values for errors:\n\n* `is required`\n* `is the wrong type`\n* `has additional items`\n* `must be FORMAT format` (FORMAT is the `format` property from the schema)\n* `must be unique`\n* `must be an enum value`\n* `dependencies not set`\n* `has additional properties`\n* `referenced schema does not match`\n* `negative schema matches`\n* `pattern mismatch`\n* `no schemas match`\n* `no (or more than one) schemas match`\n* `has a remainder`\n* `has more properties than allowed`\n* `has less properties than allowed`\n* `has more items than allowed`\n* `has less items than allowed`\n* `has longer length than allowed`\n* `has less length than allowed`\n* `is less than minimum`\n* `is more than maximum`\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"}