showing results for - "json schema verify 2fajv"
Dounia
01 Jul 2020
1// or ESM/TypeScript import
2import Ajv from "ajv"
3// Node.js require:
4const Ajv = require("ajv")
5
6const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
7
8const schema = {
9  type: "object",
10  properties: {
11    foo: {type: "integer"},
12    bar: {type: "string"}
13  },
14  required: ["foo"],
15  additionalProperties: false,
16}
17
18const validate = ajv.compile(schema)
19const valid = validate(data)
20if (!valid) console.log(validate.errors)