This package implements a JSON Schema validator.
npm install @json-schema-tools/validator
import Validator, { ValidatorErrors, ReferenceError } from "@json-schema-tools/validator"
import { JSONSchema } from "@json-schema-tools/meta-schema";
const mySchema: JSONSchema = {
title: "baz",
type: "object",
properties: {
foo: {
title: "foo",
type: "array",
items: { type: "string" }
},
bar: {
title: "bar",
anyOf: [
{ title: "stringerific", type: "string" },
{ title: "numberoo", type: "number" }
]
}
}
};
const valid = validator(mySchema, { foo: ["hello", "world" ], bar: 1 });
// true
const invalid = validator(mySchema, { foo: ["hello", "world" ], bar: true });
// invalid instanceof ValidationErrors === true
// invalid.errors is an array of the error types
See https://json-schema-tools.github.io/validator/ for typedocs
How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.
Generated using TypeDoc