vtypes-json
v1.0.0
Published
Additional constraints for validate.js
Downloads
7
Maintainers
Readme
vtypes-json
"json" validation for validate.js
About
The json
validator attempts to ensure that the input is a valid json.
Installation
Using npm:
$ npm i --save vtypes-json
const validate = require('validate.js');
const json = require('vtypes-json');
// you can then proceed to register the required validators.
validate.validators.json = json;
Usage
validate({}, {attr: {json: true}});
// => undefined
validate({attr: 'foo'}, {attr: {json: true}});
// => {attr: ["Attr must be a valid JSON string"]}
validate({attr: '{"foo": "bar"}', {attr: {json: true}});
// => undefined
For more examples, check out the test files in this package's source folder.
Available Options
| name | type | default | description |
| ------- | ------ | ----------------------------- | ------------- |
| message | string | must be a valid JSON string
| Error message |
License
vtypes-json
is MIT licensed