classic / json-validator
Fast and intuitive json validator
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/classic/json-validator
Requires
- php: >=7.2
- ext-bcmath: *
- ext-mbstring: *
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2025-12-17 17:02:28 UTC
README
composer req classic/json-validator
Code
$validator = ValidationFactory::makeValidator([ 'shemaMap' => [ CityLocatesInEuropeCustomSchema::class => new CityLocatesInEuropeCustomHandler() ] ]); $sf = $validator->getSchemaFactory(); $schema = $sf->object([ 'array' => $sf->array($sf->string()->email())->min(5)->max(10), 'city' => $sf->pipeline([ $sf->string()->enum(['Kiev', 'London', 'New York']), new CityLocatesInEuropeCustomSchema() ]), 'moneyStringRepresentation' => $sf->numeric()->onlyString()->notNegative(), 'nullableValue' => $sf->object()->nullable(), 'optionalValue' => $sf->array()->optional(), 'integer' => $sf->int()->gte(500), ]); $schema = $sf->object(['data' => $schema]); try { $validator->validate($value, $schema); } catch (ValidationException $exception) { $errors = $exception->getErrors(); }
Data
{
"data": {
"array": [
"elijah4freelance@gmail.com",
"support"
],
"city": "Paris",
"moneyStringRepresentation": "6000.00",
"nullableValue": null,
"integer": 400
}
}
Errors
[
[
'path' => 'data.array',
'message' => 'array.min',
'info' => [
'min' => 2,
],
],
[
'path' => 'data.array.1',
'message' => 'string.email',
],
[
'path' => 'data.city',
'message' => 'string.enum',
'info' => [
'enum' => [
'Kiev',
'London',
'New York',
],
],
],
[
'path' => 'data.integer',
'message' => 'number.gte',
'info' => [
'value' => '500',
],
],
];