Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahungrynoob/jsonschema
A node package based on jsonschema-rs for performing JSON schema validation
https://github.com/ahungrynoob/jsonschema
json-schema napi-rs nodejs rust
Last synced: 3 months ago
JSON representation
A node package based on jsonschema-rs for performing JSON schema validation
- Host: GitHub
- URL: https://github.com/ahungrynoob/jsonschema
- Owner: ahungrynoob
- License: mit
- Created: 2021-10-26T11:18:36.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T05:01:17.000Z (almost 2 years ago)
- Last Synced: 2024-09-29T01:29:33.494Z (4 months ago)
- Topics: json-schema, napi-rs, nodejs, rust
- Language: TypeScript
- Homepage:
- Size: 520 KB
- Stars: 51
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `@node-rs/jsonschema`
![https://github.com/ahungrynoob/jsonschema/actions](https://github.com/ahungrynoob/jsonschema/workflows/CI/badge.svg)
![](https://img.shields.io/npm/dm/@node-rs/jsonschema.svg?sanitize=true)> A node package based on jsonschema-rs for performing JSON schema validation.
## Bench
**[ajv](https://github.com/ajv-validator/ajv) is much faster than this lib.**
### Hardware
```
Model Name: MacBook Pro
Model Identifier: MacBookPro16,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 2.6 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Hyper-Threading Technology: Enabled
Memory: 32 GB
```
### Result
```
Running "Validate Sync" suite...
Progress: 100%@node-rs/jsonschema::validate:
2 642 863 ops/s, ±1.42% | slowest, 92.86% slowerajv::validate:
36 997 776 ops/s, ±0.46% | fastestFinished 2 cases!
Fastest: ajv::validate
Slowest: @node-rs/jsonschema::validate
```## Install
```
yarn add @node-rs/jsonschema
```## Support matrix
| Operating Systems| node12 | node14 | node16 |
| ---------------- | ------ | ------ | ------ |
| Windows x64 | ✓ | ✓ | ✓ |
| Windows x32 | ✓ | ✓ | ✓ |
| Windows arm64 | ✓ | ✓ | ✓ |
| macOS x64 | ✓ | ✓ | ✓ |
| macOS arm64 | ✓ | ✓ | ✓ |
| Linux x64 gnu | ✓ | ✓ | ✓ |
| Linux x64 musl | ✓ | ✓ | ✓ |
| Linux arm gnu | ✓ | ✓ | ✓ |
| Linux arm64 gnu | ✓ | ✓ | ✓ |
| Linux arm64 musl | ✓ | ✓ | ✓ |
| Android arm64 | ✓ | ✓ | ✓ |
| FreeBSD x64 | ✓ | ✓ | ✓ |## Usage
```javascript
const { compile } = require("@node-rs/jsonschema");const schema = {
type: 'object',
properties: {
foo: { type: 'integer' },
bar: { type: 'string' },
},
required: ['foo'],
additionalProperties: false,
};const input = JSON.stringify({
foo: 1,
bar: 'abc',
})const exceptionInput = JSON.stringify({
foo: 'abc',
bar: 1,
})const validator = compile(schema);
// check whether the input meet schema
const result = validator(input);
console.log(result); // trueconst result = validator(exceptionInput);
console.log(result); // false
```## API
```typescript
export declare class JSONSchema {
isValid(input: any): boolean
}export const compile: (schema: any) => (input: string) => boolean
```