illuminate/json-schema
Laravel Illuminate JSON Schema package for validating, building, and working with JSON Schema definitions. Designed to integrate with the Illuminate ecosystem, providing a clean PHP API for schema creation, checking, and tooling-friendly workflows.
Install the package via Composer (composer require illuminate/json-schema) and start validating JSON data using the core JsonSchemaValidator class. For a Laravel-native feel, define your schema as an array or load it from a file, then call validate($data, $schema, true)—note the strict mode flag is required to get meaningful errors. If you prefer the facade pattern, register 'JsonSchema' => Illuminate\Support\Facades\JsonSchema::class in config/app.php. First use case: validating incoming API payloads against a well-defined contract before processing.
storage/app/schemas/ (e.g., user.create.json) and load them via a dedicated SchemaLoader service to keep validation logic declarative and version-controlled.FormRequest classes, override validationAttributes() and inject the validator into rules()—return $validator->getErrors() as validation errors.ValidateJsonSchema middleware to enforce schema compliance across entire API routes, especially useful for webhook endpoints or external integrations.confirmed, different).JsonSchemaValidator::normalizeErrors($errors) to transform verbose JSON Schema error objects into Laravel-friendly ['field' => 'message'] arrays for consistent API responses.true as the third argument to validate()—a common source of confusion.uuid, email, or date-time are validated only if the underlying justinrainbow/json-schema library supports them; custom formats require overriding JsonSchemaValidator::validateFormat() or preprocessing.JsonSchema by default—add it manually in config/app.php under aliases.rememberForever() or a custom cache key.getErrors() returns a deeply nested array (one entry per violation)—write a dedicated error transformer to avoid duplicating error-shape logic across controllers.justinrainbow/json-schema dependency and test thoroughly in staging.How can I help you explore Laravel packages today?