How to use the json-schema/lib/validate.coerce function in json-schema

To help you get started, we’ve selected a few json-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github persvr / perstore / coerce.js View on Github external
require("json-schema/lib/validate").coerce = function(instance, schema){
	switch(schema.type){
		case "string": 
			instance = instance ? instance.toString() : ""; 
			break;  
		case "number":
			if(!isNaN(instance)){ 
				instance = +instance;
			}
			break;
		case "boolean": 
			instance = !!instance;
			break; 
		case "null": 
			instance = null;
			break; 
		case "object":