urbanminded / json-verifier
Lightweight JSON verifier
v1.1.0
2020-09-24 14:08 UTC
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-06-25 22:13:03 UTC
README
use JSONVerifier\Verifier; $schema = [ // 'name' must be a string 'name' => 'string', // 'age' is an optional key. // if present it must be an integer. '?age' => 'int', // 'favouriteFood' is an optional key. // if present it must be a string or null. '?favouriteFood' => '?string', // 'pets' must be an array of objects matching the // prescribed shape. 'pets' => Verifier::arrayOf('string', [ 'name' => 'string', 'species' => 'string' ]) ]; $verifier = new Verifier(); $verifier->verifyObject($schema, [ 'name' => 'Jason', 'favouriteFood' => null, 'pets' => [ 'Dora', ['name' => 'Ruby', 'species' => 'cat'], ['name' => 'Byron', 'species' => 'cat'], ['name' => 'Mitzi', 'species' => 'cat'], ] ]);
Installation
composer require urbanminded/json-verifier