The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started


Upgrade Guide

Simple Example

To demonstrate how to use this package, let’s validate some JSON against the JSON that defines the JSON schema itself.

First we create a dereferencer, and dereference the schema. This resolves any JSON like {"$ref" "#"} into reference objects, which are required for the validator to resolve $ref keywords properly. Make sure you installed league/json-reference if you are using references.

Next we create the validator. The first argument is the data we are validating. The second argument is the dereferenced schema.

Once the validator is created you can call $validator->passes() or $validator->fails() to validate the schema. If the validator fails, you can view the errors by calling $validator->errors().


$dereferencer  = League\JsonReference\Dereferencer::draft4();
$schema        = $dereferencer->dereference('');
$data          = json_decode('{ "id": "" }');

$validator     = new League\JsonGuard\Validator($data, $schema);

if ($validator->fails()) {
    $errors = $validator->errors();