SJOT for JS in action
JSON source
This JSON object has an embedded SJOT schema @sjot with a @root type that describes its valid PersonDetails content precisely, such as the property types, which properties are optional (e.g. tags? and age?), default values for properties (e.g. id?999), inheritance (PersonDetails extends Person), and which properties should occur @all together (e.g. tags and phone should be used together or not at all):
JS code to parse JSON and validate the data using the embedded @sjot
var obj = JSON.parse(text);
try {
SJOT.validate(obj);
document.getElementById("demo").innerHTML = obj.id + "<br>" + obj.name + "<br>" + obj.street + "<br>" + obj.phone;
} catch (e) {
document.getElementById("demo").innerHTML = '<pre>' + e + '</pre>';
}
SJOT in JSON live validation test
SJOT schema live valid JSON data test
SJOT schema live invalid JSON data test
Invalid JSON data: