anothersimplejsonvalidator

1.0.1 • Public • Published

A simple JSON validator.

installation

npm i anothersimplejsonvalidator
console.log(require('anothersimplejsonvalidator')(1, {type : 'number'}))

object

object = {
    someNumber : 10,
    someBool : false,
    anotherObject : {
        someStr : 'John Doe,
        arr : []
    }
}

schema syntax

schema = {
    type : 'object',
    property : {
        someNumber : { type : 'number' },
        someBool : { type : 'boolean' },
        anotherObject : {
            type : 'object',
            property : {
                someStr : { type : 'string' },
                arr : { type : 'array' }
            }
        }
    }
}

options

simpleJsonValidator(object, schema, { throwError : true }) //will throw an error if validation failed
simpleJsonValidator(object, schema) //will simply return true or false

Optional custom validators

type property example
string regex { type : 'string', regex : /myEmail@gmail.com/ }
boolean expected { type : 'string', expected : false }
number min, max { type : 'number', min : 5, max : 10000 }
array minLength, maxLength { type : 'array', maxLength : 20 }

Keywords

none

Install

npm i anothersimplejsonvalidator

DownloadsWeekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

13.1 kB

Total Files

4

Last publish

Collaborators

  • mukul11a47