Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including hypermedia-validator with all npm packages installed. Try it out:

var hypermediaValidator = require("hypermedia-validator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

hypermedia-validator v0.3.0

Validate json data against schemas

Hypermedia Schema validation

Requires node >= 0.12

Use prmd or 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

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free