Remi Collet 14c9472c2b Fix #291 failed tests with lestest PHP
Since 5.6.24, 7.0.9, 7.1.0beta1, negative timestamps are valid.
2016-07-21 18:37:10 +02:00
2012-05-13 22:15:26 -07:00
2015-11-08 19:17:40 +01:00
2016-04-27 11:38:10 +07:00
2016-03-25 09:12:24 -05:00
2016-04-15 10:02:09 +02:00

JSON Schema for PHP

Build Status Latest Stable Version Total Downloads

A PHP Implementation for validating JSON Structures against a given Schema.

See json-schema for more details.

Installation

Library

$ git clone https://github.com/justinrainbow/json-schema.git

Dependencies

Composer (will use the Composer ClassLoader)

$ wget http://getcomposer.org/composer.phar
$ php composer.phar require justinrainbow/json-schema:~2.0

Usage

<?php

// Get the schema and data as objects
// If you use $ref or if you are unsure, resolve those references here
// This modifies the $schema object
$refResolver = new JsonSchema\RefResolver(new JsonSchema\Uri\UriRetriever(), new JsonSchema\Uri\UriResolver());
$schema = $refResolver->resolve('file://' . realpath('schema.json'));

$data = json_decode(file_get_contents('data.json'));

// Validate
$validator = new JsonSchema\Validator();
$validator->check($data, $schema);

if ($validator->isValid()) {
    echo "The supplied JSON validates against the schema.\n";
} else {
    echo "JSON does not validate. Violations:\n";
    foreach ($validator->getErrors() as $error) {
        echo sprintf("[%s] %s\n", $error['property'], $error['message']);
    }
}

Running the tests

$ vendor/bin/phpunit
Description
No description provided
Readme MIT 3.7 MiB
Languages
PHP 100%