ergebnis / json-schema-validator
Provides a JSON schema validator, building on top of justinrainbow/json-schema.
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- ext-json: *
- ergebnis/json: ^1.2.0
- ergebnis/json-pointer: ^3.4.0
- justinrainbow/json-schema: ^5.2.12 || ^6.0.0
Requires (Dev)
- ergebnis/data-provider: ^3.6.0
- ergebnis/license: ^2.7.0
- ergebnis/php-cs-fixer-config: ^6.63.3
- ergebnis/phpunit-slow-test-detector: ^2.25.0
- ergebnis/rector-rules: ^1.18.4
- fakerphp/faker: ^1.24.0
- infection/infection: ~0.26.6
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.2.15
- phpstan/phpstan-deprecation-rules: ^2.0.5
- phpstan/phpstan-phpunit: ^2.0.18
- phpstan/phpstan-strict-rules: ^2.0.12
- phpunit/phpunit: ^9.6.20
- rector/rector: ^2.6.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main / 4.6.x-dev
- 4.6.0
- 4.5.1
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.0.0
- 1.0.0
- dev-enhancement/reference-namespaced-symbols-relative-to-namespace-prefix
- dev-enhancement/phpstan-rector
- dev-enhancement/rector-default-command
- dev-enhancement/php-versions
- dev-enhancement/workflow-badges
- dev-fix/psalm
- dev-enhancement/allow-installation-on-php-8-6
- dev-fix/changelog
- dev-fix/composer-normalize-phar
- dev-fix/monthly-downloads-badge
This package is auto-updated.
Last update: 2026-09-24 19:43:04 UTC
README
This project provides a composer package with 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
arrayof 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\Json; use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator; $json = Json::fromFile('composer.json'); $schema = Json::fromString(file_get_contents('https://getcomposer.org/schema.json')); $jsonPointer = Pointer\JsonPointer::document(); $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
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @ergebnis.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.