json-schema/validate.php
2008-12-11 12:56:29 +00:00

27 lines
572 B
PHP

<?php
require_once('JsonSchema.php');
require_once('JsonSchemaUndefined.php');
Dbg::$quietMode = true;
if($_REQUEST['schema']) {
$schema = json_decode($_REQUEST['schema']);
if(!$schema) {
trigger_error('Could not parse the SCHEMA object.',E_USER_ERROR);
}
}
else {
$schema = null;
}
$json = json_decode($_REQUEST['json']);
if(!$json) {
trigger_error('Could not parse the JSON object.',E_USER_ERROR);
}
$result = JsonSchema::validate(
$json,
$schema
);
header('Content-type: application/x-json');
echo json_encode($result);
?>