json-validator
Validates JSON against a schema
This is a work in progress, use with caution.
Go check the demo: https://json-validator-demo.herokuapp.com/
Introduction
This module helps you to check if a JSON or a javascript object conforms to a given pattern, in an async or sync manner. Also it helps you make changes to this object (e.g. remove mask from a given field, or a assign a default value for a field).
Actually this library delegates complex validations to validator.js, this means you can use any of their methods. If you are using their validators make sure enclose parameters into square brackets []
:
Contributors
Instalation
npm install --save json-validator
Usage & Examples
var jsv = ; var userSchema = name: required: true trim: true //will trim the value before next validations isLength: 4 10 //name must have between 4 and 10 characters { //you can have custom validator too return isValid: true message: 'your custom message' ; } email: required: true isEmail: true { ; } myNumber: default: '42' description: required: true escape: true //escapes HTML characters favoriteColors: required: false enum: 'blue' 'black' 'orange' ipsAllowed: trim: true isIP: true var user = name: 'Gammasoft' email: 'contact@gammasoft.com.br' description: 'This module is <b>awesome</b>' favoriteColors: 'green' 'blue' ipsAllowed: '192.168.1.102 ' '0.0.0.0' 'thisIsNotAnIp'; jsv;
The above example gives the following output:
Related Projects
http://opensource.gammasoft.com.br (full list of my projects in GitHub)
License
The MIT License (MIT)
Copyright (c) 2014 Gammasoft Desenvolvimento de Software Ltda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.