1.0.0 • Published 7 years ago

vtypes-json v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

vtypes-json

"json" validation for validate.js

npm package vtypes

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

nametypedefaultdescription
messagestringmust be a valid JSON stringError message

License

vtypes-json is MIT licensed