Cast data against JSON Schema with ajv
npm install sqem
{
"type": "object",
"dynamicDefaults": {
"id": "shortid"
},
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
},
"required": [
"name"
],
"additionalProperties": false
}
const cast = sqem(schema)
cast({
name: 'Exo',
age : '40',
size: 2
})
// > Right { name: 'Exo', age: 40, id: 'f3ytunvu1' }
cast({ size: 2 })
// > Left { code: 422 }
Params
schema
- JSON Schemainput
- Data to validate
MIT