aipng / json-validator
json validator (based on opis/json-schema)
1.2
2024-02-19 23:22 UTC
Requires
- php: >= 8.1
- nette/utils: ^v4.0.0
- opis/json-schema: ^2.2
Requires (Dev)
- nette/di: ^3.2
- nette/schema: ^1.3
- phpstan/phpstan: ^1.3
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.5.10
This package is auto-updated.
Last update: 2024-10-20 00:50:26 UTC
README
JSON validator (based on opis/json-schema)
Installation
composer require aipng/json-validator
Usage
Simple - validate JSON input against simple JSON schema
use \AipNg\JsonValidator\JsonValidator; $validator = new JsonValidator; $validator->validate($jsonData, $jsonSchemaPath);
Validator provides simple mapping of JSON schema indentificators to a directory structure, eg:
- https://example.org/schemas/foo.json ->
/<my-project-schema-path/foo.json
- https://example.org/schemas/bar.json ->
/<my-project-schema-path/bar.json
use \AipNg\JsonValidator\JsonValidator; $validator = new JsonValidator(10, 'https://example.org/schemas/', '/<my-project-schema-path/'); $validator->validate($jsonData, $jsonSchemaPath);
Nette extension
Register
extensions: jsonValidator: AipNg\JsonValidator\DI\JsonValidatorExtension
Configure
jsonValidator: max_errors: 10 # maximum of returned errors mapping: # maps JSON schema identificators to directory structure prefix: https://www.example.org/api/schema/ directory: %wwwDir%/../src/schema/