Created
January 17, 2017 21:33
-
-
Save miike/952db7a1557d664756fea5389a759ee6 to your computer and use it in GitHub Desktop.
Validating JSON schemas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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