- How do I install carsdotcom/laravel-json-schema in a Laravel application?
- Install the package with Composer using composer require carsdotcom/laravel-json-schema. Laravel package discovery should register the service provider automatically. Publish any package configuration if your application needs to customize schema paths or validation behavior. After installation, run your existing test suite to confirm request validation still behaves as expected.
- Which Laravel and PHP versions does this JSON Schema package support?
- The package is built for Laravel applications, but exact Laravel and PHP version constraints are defined in its composer.json and release notes. Check the repository compatibility information before upgrading, especially if you are on older Laravel releases. For production use, pin a version that matches your framework and PHP runtime and verify it in a staging environment.
- How do I validate Laravel request data against a JSON Schema?
- Use the package to apply a reusable JSON Schema to request data or other payloads in your Laravel validation flow. Validation failures are returned as Laravel-native errors, so they fit existing form request and API error handling patterns. This is useful when you want a schema contract rather than duplicating many individual validation rules.
- Can this package enforce API contracts and response payload rules?
- Yes, the package is intended for validating request data and other payloads against reusable schemas. That makes it a good fit for enforcing API contracts and keeping payload rules consistent across endpoints. You can validate outgoing structures in tests or application checks where response shape matters.
- What is normalizeWithJsonSerializable in v3.0.1 and should I disable it?
- The normalizeWithJsonSerializable flag was added in v3.0.1 and defaults to true, preserving the existing JsonSerializable normalization behavior. Disabling it uses Opis Helper::toJson for lower memory use and faster serialization on extremely large payloads. Treat false as an opt-in performance optimization for specific high-volume paths, not a global default, because it can miss unusual JsonSerializable contracts such as Models or JsonModels.
- Is upgrading to carsdotcom/laravel-json-schema v3.0.1 a breaking change?
- No, v3.0.1 is described as a low-risk, backwards-compatible feature release. The new normalization flag defaults to true, so existing installations should upgrade without code changes. The safe path is to upgrade first, run your normalization and validation tests, and only then evaluate disabling JsonSerializable handling where justified.
- What are the risks of setting normalizeWithJsonSerializable to false?
- Setting the flag to false can produce incomplete or differently shaped payloads when unusual JsonSerializable contracts such as Eloquent models or custom JsonModels are involved. That may break downstream consumers, validation, signatures, or cached representations. Adopt false only on narrow, well-tested paths where payload size and memory pressure are proven concerns, and keep rollback simple by restoring the default true.
- How should I test JSON Schema validation in a Laravel application?
- Write feature tests that submit valid and invalid payloads through the same Laravel request or validation path used in production. Assert both the validation result and the Laravel-native error messages your API returns. If you use the new normalization flag, test affected endpoints with normalizeWithJsonSerializable both true and false and compare payload shapes against current production outputs.
- Does this JSON Schema package work with Eloquent models and custom JsonSerializable payloads?
- By default, the package preserves JsonSerializable normalization semantics, so Eloquent models and custom JsonSerializable implementations should continue to serialize as before. The risk appears only when you explicitly disable that behavior with normalizeWithJsonSerializable set to false. Add regression tests for model-backed endpoints and any custom JsonModels before changing the flag.
- What alternatives exist for JSON Schema validation in Laravel?
- Common alternatives include using Opis JSON Schema or justinrainbow/json-schema directly, or building custom Laravel validation rules around a schema library. This package is useful when you want JSON Schema validation integrated with Laravel-native errors and reusable schemas. Compare alternatives based on schema draft support, error message quality, Laravel version compatibility, and long-term maintenance.