Provides a JSON schema validator, building on top of justinrainbow/json-schema
.
Run
$ composer require ergebnis/json-schema-validator
If you have used the validator from justinrainbow/json-schema
before, you might have observed that it has a few flaws:
- The validator is stateful.
- The validator requires decoding JSON strings before validating them.
- The validator returns an
array
of errors, where each error is anarray
.
This package delegates the validation to justinrainbow/json-schema
and provides a friendlier interface.
<?php
declare(strict_types=1);
use Ergebnis\Json\SchemaValidator;
$json = SchemaValidator\Json::fromFile('composer.json');
$schema = SchemaValidator\Json::fromString(file_get_contents('https://getcomposer.org/schema.json'));
$jsonPointer = SchemaValidator\JsonPointer::empty();
$schemaValidator = new SchemaValidator\SchemaValidator();
$result = $schemaValidator->validate(
$json,
$schema,
$jsonPointer
);
var_dump($result->isValid()); // bool
var_dump($result->errors()); // flat list of `ValidationError` value objects
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.md
.
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
馃摤 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.