https://github.com/figadore/json-schema-validator
Validate json data against json schema
https://github.com/figadore/json-schema-validator
Last synced: over 1 year ago
JSON representation
Validate json data against json schema
- Host: GitHub
- URL: https://github.com/figadore/json-schema-validator
- Owner: figadore
- Created: 2016-02-25T21:45:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-19T18:07:44.000Z (about 10 years ago)
- Last Synced: 2025-04-10T05:12:27.734Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hypermedia Schema validation
Requires node >= 0.12
Use [prmd](https://github.com/interagent/prmd) or [schema-generator](https://hub.docker.com/r/shinydocker/schema-generator/) to generate JSON schemas (this package works for JSON schemas in general, not just for prmd's hypermedia schemas). Validation is done with the [z-schema library](https://github.com/zaggino/z-schema)
Schemas fetched from http uri's are cached to file if node has write permission to the `schemas` directory
## Usage
`npm install --save hypermedia-validator`
```
var validator = require('hypermedia-validator');
var car = {
id: 33,
make: "Ford",
model: "Taurus",
color: "black"
};
validator.validate(car, 'http://example.com/schemas/main#definitions/car', function (err) {
if (err) {
// Validation details are stashed away in err.detail, not shown in console when thrown
console.log("Error during validation", car, util.inspect(err, false, null));
throw err;
}
});
```
### CLI
```
npm install -g hypermedia-validator
validate cars.json file://schema.json#definitions/car/definitions/cars
// Or
validate cars.json http://example.com/schemas/main#definitions/car/definitions/cars
```
## Development
### Testing
run `npm test`