Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marvinhagemeister/fast-json-validation
A faster way to validate json objects
https://github.com/marvinhagemeister/fast-json-validation
json json-schema schema validation
Last synced: 28 days ago
JSON representation
A faster way to validate json objects
- Host: GitHub
- URL: https://github.com/marvinhagemeister/fast-json-validation
- Owner: marvinhagemeister
- License: mit
- Created: 2017-11-09T09:58:46.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-09T11:36:12.000Z (about 7 years ago)
- Last Synced: 2024-04-26T21:21:13.864Z (8 months ago)
- Topics: json, json-schema, schema, validation
- Language: TypeScript
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Fast JSON Validator
A **10x faster** way to validate json objects with a simple ast. This library
is intended to be used as a transpilation target.| Library | Test Name | Single Run | Benchmark | Size (gzip) |
|---|---|---|---|---|
| [ajv](https://github.com/epoberezkin/ajv) | fstab | 22.926ms | 17,550 ops/sec | 2.6kb |
| fast-json-validator | fstab | **0.67ms** | **149,795 ops/sec** | **1.6kb** |## Installation
```bash
# npm
npm install --save fast-json-validator# yarn
yarn add fast-json-validator
```## Usage
Although one can construct the schema by hand, it is **not recommended**. This
library is more intended as a transpile target from other languages (think
GraphQL, TypeScript, Flow,...).```js
import * as v from "fast-json-validate";const data = {
"/": "bar",
"/bar/bob": {
type: "ext4"
},
}// This should be generated by your library
const schema = v.record(
v.union([
v.string(),
v.object(
{
type: v.enum(["ext4", "ext4"])
},
{ required: ["type"]}
)
]),
{ type: v.regexType(/^\//})
);v.validate(data, schema);
// =>
// { error: undefined, valid: true}
```## FAQ
**Q: Why another tool to validate json data?**
This project was born because I got frustrated with creating automatic mocks
out of `json-schema` definitions. The `json-schema` grammar allows to create
conflicting schemas that never validate, is slow to verify (the validator has
to make a lot of educated guesses), validation libraries tend to be a lot
bigger than necessary, and are difficult to parse.## License
`MIT`, see [License file](LICENSE.md).