jsonschema-validate-default
just a tiny libary based on jsonschema libary that allows you to test if your object is valid and if so to combine it with your deafults data
usage example
lazy
const validate = ; // create your schemaconst json = "type": "object" "properties": "id": "type": "string" "default": "id" "required": true "age": "default": 30 "type": "integer" let validObject = // validObject.instance => {id:"maty",age:30} let validObject = // validObject.instance => {id:"maty",age:20} let validObject = //=> {id:"maty",age:20} => error:{valid:false, errorDescription:"id is required"} let validObject = //=> error:{valid:false, errorDescription:"id is not a string error "}
with schema initiation before
let validateWithSchema = ;let obj= id: "12345" info: age: 6 ;console;
ignore null option
ignorenull option allows you to set the default param in the return object although the value is defiend
validateWithSchema = ;console //=> {"id":"12345","info":{"age":6,"familyName":null}}console //=>{"id":"12345","info":{"age":6,"familyName":"unknown"}}