Answers for "json to schema javascript"

0

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));
Posted by: Guest on August-01-2021

Code answers related to "json to schema javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language