How to use jsonschema

Comprehensive jsonschema code examples:

How to use jsonschema.Validator:

46
47
48
49
50
51
52
53
54
55
56
    }
    done();
});


gulp.task('validateTranslationFiles', (done) => {
    const validator = new Validator();
    const schema = {
        type: 'object',
        patternProperties: {
            '^[a-z0-9.]*': {

How to use jsonschema.validate:

54
55
56
57
58
59
60
61
62
63
// arrive as strings from querystring, but we want as int/bool
if (q.minSalary !== undefined) q.minSalary = +q.minSalary;
q.hasEquity = q.hasEquity === "true";

try {
  const validator = jsonschema.validate(q, jobSearchSchema);
  if (!validator.valid) {
    const errs = validator.errors.map(e => e.stack);
    throw new BadRequestError(errs);
  }