Skip to content

Instantly share code, notes, and snippets.

@miike
Created January 17, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miike/952db7a1557d664756fea5389a759ee6 to your computer and use it in GitHub Desktop.
Save miike/952db7a1557d664756fea5389a759ee6 to your computer and use it in GitHub Desktop.
Validating JSON schemas
var Validator = require('jsonschema').Validator;
var v = new Validator();
var collectSchema = {
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Additional properties about how audio/video was consumed when embedded in other content (such as in an article)",
"self": {
"vendor": "au.net.abc.snowplow",
"name": "embed_context",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": {
"contentid": {
"type" : "string",
"maxLength": 100
},
"contentsource": {
"type" : "string",
"maxLength": 255
},
"contenttype": {
"type" : "string",
"maxLength": 255
}
},
"required": ["contentid","contentsource","contenttype"],
"additionalProperties": false
}
var instance = {
"contentid": "test",
"contentsource": "test2",
"contenttype": "test3"
}
v.addSchema(collectSchema, '/collect');
console.log(v.validate(instance, collectSchema));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment