Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/json-schema-tools/validator

JSONSchema validator
https://github.com/json-schema-tools/validator

json-schema typescript validator

Last synced: 1 day ago
JSON representation

JSONSchema validator

Awesome Lists containing this project

README

        

# JSON Schema Validator


CircleCI branch

npm
GitHub release
GitHub commits since latest release

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 });
// 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

### 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.