ergebnis / json-schema-validator
Provides a JSON schema validator, building on top of justinrainbow/json-schema.
Installs: 1 779 342
Dependents: 3
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 0
Open Issues: 2
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- ergebnis/json-pointer: ^3.0.0
- justinrainbow/json-schema: ^5.2.10
Requires (Dev)
- ergebnis/composer-normalize: ^2.21.0
- ergebnis/data-provider: ^1.2.0
- ergebnis/license: ^1.2.0
- ergebnis/php-cs-fixer-config: ~4.4.0
- fakerphp/faker: ^1.19.0
- infection/infection: ~0.26.6
- phpunit/phpunit: ~9.5.19
- psalm/plugin-phpunit: ~0.16.1
- vimeo/psalm: ^4.22
This package is auto-updated.
Last update: 2022-08-02 22:10:27 UTC
README
Provides a JSON schema validator, building on top of justinrainbow/json-schema
.
Installation
Run
$ composer require ergebnis/json-schema-validator
Usage
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
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Curious what I am building?
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.