Node.js Tutorial to Validate JSON Schema Objects Using is-my-json-valid Library in Javascript Full Project For Beginners

 

 

npm i is-my-json-valid

 

 

After installing this library you need to make an index.js file and copy paste the following code

 

 

index.js

 

 

var validator = require('is-my-json-valid')
 
var validate = validator({
  required: true,
  type: 'object',
  properties: {
    hello: {
      required: true,
      type: 'string'
    }
  }
})
 
console.log('should be valid', validate({hello: 'world'}))
console.log('should not be valid', validate({hello:56}))

 

 

Leave a Reply