vtypes-json

1.0.0 • Public • Published

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

name type default description
message string must be a valid JSON string Error message

License

vtypes-json is MIT licensed

Package Sidebar

Install

npm i vtypes-json

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • geraldyeo