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.
Avoid if:
opis/json-schema are actively maintained).swaggest/php-json-schema or json-schema-validator instead).spatie/fork or symfony/validator for modern alternatives).Consider if:
"This package lets us enforce strict data quality standards across our APIs and internal systems, reducing errors and compliance risks. By validating JSON payloads against schemas (like a 'contract' for data), we catch issues early—saving dev time and improving reliability. It’s a lightweight, open-source solution that replaces error-prone custom checks, with minimal overhead. Think of it as 'unit tests for your data.' Alternatives exist, but this one is proven (passes the full Draft 4 test suite) and integrates seamlessly with our PHP stack."
*"Pros:
/user/address/city).Trade-offs:
opis/json-schema instead.swaggest/php-json-schema.Use Cases:
POST /users requires email field).if (strlen($input) > 10 && ...)) with maintainable schemas.Quick Start:
composer require league/json-guard
$validator = new \League\JsonGuard\Validator(
json_decode($request->getContent()),
json_decode(file_get_contents('schema.json'))
);
if ($validator->fails()) {
throw new \RuntimeException('Invalid data: ' . json_encode($validator->errors()));
}
```*
**Alternatives**:
- **Active maintenance needed?** → `opis/json-schema` or `swaggest/php-json-schema`.
- **Need Draft 7+?** → Same as above.
- **PHP 8.2+ with types?** → `spatie/fork` or Symfony’s Validator component.
**Recommendation**: Use this for Draft 4 compliance with minimal friction. If you’re starting a new project, evaluate modern alternatives."*
How can I help you explore Laravel packages today?