Web Interfaces of PROSUME

demo.php 532B

123456789101112131415161718
  1. <?php
  2. require __DIR__ . '/../vendor/autoload.php';
  3. $data = json_decode(file_get_contents('data.json'));
  4. // Validate
  5. $validator = new JsonSchema\Validator();
  6. $validator->check($data, (object) array('$ref' => 'file://' . realpath('schema.json')));
  7. if ($validator->isValid()) {
  8. echo "The supplied JSON validates against the schema.\n";
  9. } else {
  10. echo "JSON does not validate. Violations:\n";
  11. foreach ($validator->getErrors() as $error) {
  12. echo sprintf("[%s] %s\n", $error['property'], $error['message']);
  13. }
  14. }