https://github.com/xibitdigital/json-schema-util
JSON schema validator utility
https://github.com/xibitdigital/json-schema-util
json-schema nodejs validation
Last synced: 3 months ago
JSON representation
JSON schema validator utility
- Host: GitHub
- URL: https://github.com/xibitdigital/json-schema-util
- Owner: xibitdigital
- Created: 2017-08-10T17:31:19.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T17:59:06.000Z (almost 9 years ago)
- Last Synced: 2026-03-29T07:57:31.612Z (3 months ago)
- Topics: json-schema, nodejs, validation
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON schema util
This is a utility to validate data against a JSON schema.
# example
```js
const {validate} = require('json-schema-util');
// set a json schema
const schema = {
type: "object",
properties: {
testNum: {
type: "number"
},
testString: {
type: "string"
}
}
};
```
Validation success:
```js
const data = { testNum: 1 };
const res = validate(data, schema);
console.log(res.isValid) // true
```
Validation error:
```js
const data = { testNum: 'a', testString: 1 };
const res = validate(data, schema);
console.log(res.isValid) // false
console.log(res.errors) // {isValid: false, errors: {{ value: 'a', property: 'tesnNum', message: '...'}}};
```