Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/json-schema-tools/validator
JSONSchema validator
https://github.com/json-schema-tools/validator
json-schema typescript validator
Last synced: about 1 month ago
JSON representation
JSONSchema validator
- Host: GitHub
- URL: https://github.com/json-schema-tools/validator
- Owner: json-schema-tools
- License: apache-2.0
- Created: 2020-07-30T22:22:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-23T21:48:58.000Z (4 months ago)
- Last Synced: 2024-11-01T15:41:14.613Z (about 2 months ago)
- Topics: json-schema, typescript, validator
- Language: TypeScript
- Homepage: https://json-schema-tools.github.io/validator/
- Size: 630 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# JSON Schema Validator
This package implements a JSON Schema validator.
## Features
- dead simple
- faster than sonic
- completely synchronous
- circular reference detection & handling
- errors if it finds any $refs - use the [dereferencer](https://github.com/json-schema-tools/dereferencer) before using the validator.
- you get the json schema draft based on [meta-schema](https://github.com/json-schema-tools/meta-schema).## Getting Started
```sh
npm install @json-schema-tools/validator
``````typescript
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 });
// trueconst 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
### Contributing
How to contribute, build and release are outlined in [CONTRIBUTING.md](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification.