Get started with ajv-async CDN
MIT licensed
AJV-async is a library that provides asynchronous JSON schema validation using AJV.
Tags:- JSON
- schema
- validator
- validation
- jsonschema
- json-schema
- json-schema-validator
- json-schema-validation
- async
- asynchronous
- asynchronous validation
- ajv
- generators
- async-function
- co
- nodent
- regenerator
Stable version
Copied!
How to start using ajv-async CDN
// Include the ajv-async library from CDN
const Ajv = await import('https://cdn.cdnhub.io/ajv-async/1.0.1/ajv-async.min.js');
// Define the JSON schema
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' },
},
required: ['name', 'age'],
};
// Create a new AJV instance and compile the schema
const validate = new Ajv().compile(schema);
// Sample data to validate
const data = { name: 'John Doe', age: 30 };
// Validate the data against the schema and check for errors
const valid = validate(data);
if (valid) {
console.log('Data is valid');
} else {
console.log('Data is invalid:', validate.errors);
}
Copied!
Copied!
Copied!
Copied!