league/json-guard
Unmaintained JSON Schema validator (draft 4) for PHP. Passes the full Draft 4 test suite, supports custom rule sets, and returns helpful errors with JSON Pointers. Consider opis/json-schema or swaggest/php-json-schema as alternatives.
Pros:
opis/json-schema or swaggest/php-json-schema.FormRequest::validate()).$ref for modular schema design, useful in large Laravel applications with shared schemas (e.g., microservices, API contracts).Cons:
FormRequest facade or validation rule helpers).json_decode($data, false) (object mode) requirement, but conflicts with Laravel’s json_decode($data, true) (array mode) convention.JsonGuardValidator) to bridge Laravel’s Validator facade.symfony/polyfill-mbstring, symfony/translation for error localization). Low risk of version conflicts.maxDepth setting).opis/json-schema).json_schema extension or swaggest/php-json-schema.symfony/polyfill-mbstring).opis/json-schema or swaggest/php-json-schema?
opis/json-schema is actively maintained but may have stricter draft requirements; swaggest is lightweight but less documented.json_schema PHP extension).symfony/translation or Laravel’s Validator::extend().maxDepth settings.Validator::extend() or a custom rule (e.g., JsonGuard).
use League\JsonGuard\Validator as JsonGuardValidator;
Validator::extend('json_guard', function ($attribute, $value, $parameters, $validator) {
$schema = json_decode($parameters[0]);
$guard = new JsonGuardValidator(json_decode($value, false), $schema);
if ($guard->fails()) {
$validator->errors()->add($attribute, implode(', ', array_column($guard->errors(), 'message')));
return false;
}
return true;
});
JsonResource contracts).Illuminate\Queue\SerializesModels).json-reference for contract validation (e.g., OpenAPI/Swagger specs).league/json-guard as a dev dependency.App\Services\JsonGuardValidator) to abstract Laravel integration.opis/json-schema or swaggest/php-json-schema in a phased approach:
jsonschema-to-json-schema to convert schemas between drafts.symfony/polyfill-mbstring: May conflict with Laravel’s symfony/translation (use explicit versions).league/json-reference: Required for $ref support (add as a dependency).FormRequest validation.symfony/polyfill-mbstring and league/json-reference for updates.league/json-guard and league/json-reference.maxDepth).League\JsonReference\Dereferencer with caching).maxDepth conservatively).league/json-reference or symfony/polyfill-mbstring breaking changes may halt validation.league/json-guard API.$ref).ajv-cli for Draft 7 compatibility checks).How can I help you explore Laravel packages today?