carsdotcom/laravel-json-schema
Adds JSON Schema validation to Laravel, letting you validate request data and other payloads against reusable schemas with Laravel-native errors—ideal for enforcing API contracts and keeping payload rules consistent.
Start by confirming which layer exposes the new normalizeWithJsonSerializable option: typically the package config file after php artisan vendor:publish, or the validation/normalization entry point if your integration passes options per call. The default is true, so existing applications should behave exactly as before after upgrading to v3.0.1.
First practical use case: keep the default for normal Laravel request validation where payloads may contain Eloquent models, API resources, or custom JsonSerializable objects. Only reach for normalizeWithJsonSerializable => false when you have measured memory pressure from extremely large payloads and can guarantee the data being normalized does not rely on Laravel-specific JsonSerializable behavior.
Look first at:
JsonModel instances into validation.Use the default true path for day-to-day Laravel work. It preserves drop-in compatibility and correctly handles unusual JsonSerializable contracts such as Eloquent models and JsonModel instances.
For high-volume or large-payload endpoints, switch to false selectively rather than globally. Prefer an environment-driven config value or a dedicated validation path for those endpoints, for example:
// config/package.php
'normalize_with_json_serializable' => env('JSON_NORMALIZE_WITH_SERIALIZABLE', true),
Then disable it only where payloads are large and already plain arrays/scalars:
JSON_NORMALIZE_WITH_SERIALIZABLE=false
When using the fast Opis\Helper::toJson path, normalize model data explicitly before validation. For example, convert Eloquent models with ->toArray() or a resource before handing the payload to the validator. This keeps behavior predictable and avoids relying on implicit JsonSerializable handling.
Good integration points:
The main pitfall is silently losing Laravel-specific serialization behavior. With normalizeWithJsonSerializable => false, the package uses Opis’s Helper::toJson path, which is faster and less memory intensive but does not honor unusual JsonSerializable contracts such as Eloquent models or JsonModel. If a payload contains those objects, validation may see a different structure than expected.
Test both modes with representative payloads, especially:
JsonSerializable classes,Remember to clear cached config after changing the flag:
php artisan config:clear
If you cannot override the option per call, avoid changing the global default just to optimize one large endpoint. Use a separate config value, environment variable, or dedicated service path instead.
For debugging, compare the normalized JSON produced by both modes. A validation failure that appears only after disabling the flag usually means the payload depended on JsonSerializable behavior rather than plain array/scalar data.
Treat false as an optimization, not a default. Measure memory and response time before and after. The default true is the safe drop-in choice for existing applications upgrading to v3.0.1.
How can I help you explore Laravel packages today?