ak-json-to-joi
NPM Module to convert predefined JSON into Joi validation schema dynamically.
How to install?
How to use
const JoiSchemaBuilder = ;let JoiValidationSchema = JoiSchemaBuilder;let result = Joi
Supported Features
Types
Use any of these as types of the key
stringnumberemailarrayobjectboolean
Validations
minLength: integer valuemaxLength: integer valueoptional: true / falserequired: true / falseregex: regex patterndefault: default value
Sample JSONs
ARRAY JSON
"$array": "name": "$type":"string" "number": "$type":"number" "optional": true
OBJECT JSON
"name": "original": "$type": "string" "required": true "maxLength": 200 "nick": "$type": "string" "optional": true "default": "arshad" "phone": "$type": "number" "required": true "email": "$type": "email" "optional": true "date": "$type": "date" "minDate": "1-1-2017" "maxDate": "10-05-2018"
Note:
'type' and 'array' key in validation json should be prefixed with '$' symbol
on missing $ symbol your validation might not work.