Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

json to schema javascript

var Validator = require('jsonschema').Validator;var v = new Validator(); // Address, to be embedded on Personvar addressSchema = {  "id": "/SimpleAddress",  "type": "object",  "properties": {    "lines": {      "type": "array",      "items": {"type": "string"}    },    "zip": {"type": "string"},    "city": {"type": "string"},    "country": {"type": "string"}  },  "required": ["country"]}; // Personvar schema = {  "id": "/SimplePerson",  "type": "object",  "properties": {    "name": {"type": "string"},    "address": {"$ref": "/SimpleAddress"},    "votes": {"type": "integer", "minimum": 1}  }}; var p = {  "name": "Barack Obama",  "address": {    "lines": [ "1600 Pennsylvania Avenue Northwest" ],    "zip": "DC 20500",    "city": "Washington",    "country": "USA"  },  "votes": "lots"}; v.addSchema(addressSchema, '/SimpleAddress');console.log(v.validate(p, schema));
Source by www.npmjs.com #
 
PREVIOUS NEXT
Tagged: #json #schema #javascript
ADD COMMENT
Topic
Name
3+9 =