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

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

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: '...'}}};

```