Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Json Schema Laravel Package

justinrainbow/json-schema

Validate JSON documents against JSON Schema in PHP. Supports Draft-3, Draft-4, Draft-6 and Draft-7 (coverage varies). Install via Composer and use JsonSchema\Validator to validate data with local file $ref schemas and inspect validation errors.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • API Contract Enforcement: Enforce strict data validation for incoming API requests (e.g., REST, GraphQL, or microservices) to ensure consistency and reduce runtime errors.
  • Data Pipeline Integrity: Validate structured data (e.g., JSON payloads, config files, or database exports) in ETL pipelines or batch processing workflows.
  • Build vs. Buy: Buy—this package is production-ready, actively maintained, and avoids reinventing JSON Schema validation from scratch.
  • Self-Service Developer Tools: Embed validation in developer-facing tools (e.g., CLI tools, SDKs, or IDE plugins) to catch misconfigured inputs early.
  • Compliance & Auditability: Use CHECK_MODE_VALIDATE_SCHEMA to ensure schemas themselves adhere to standards, critical for regulated industries (e.g., finance, healthcare).
  • Type Coercion for Legacy Systems: Modernize legacy PHP systems by automatically converting loose input types (e.g., "true"bool) to match schemas, reducing manual parsing logic.
  • Roadmap for Schema Evolution: Support for Draft-7 enables future-proofing; prioritize adoption if your team uses modern JSON Schema features (e.g., $dynamicRef, contentMediaType).

When to Consider This Package

Adopt This Package If:

  • Your PHP backend consumes/produces JSON and needs runtime validation (e.g., API gateways, microservices).
  • You require support for Draft-4/6/7 (most widely used in modern APIs) or need strict compliance (e.g., CHECK_MODE_STRICT for Draft-6).
  • Your team wants to reduce bugs by validating data early (e.g., API requests, config files) with detailed error messages.
  • You need type coercion (e.g., converting "1" to 1 or "true" to true) to handle loose input formats.
  • Your project uses Laravel/Symfony and you want to integrate validation into existing frameworks (e.g., via middleware or form requests).
  • You’re building developer tools (e.g., CLI apps, SDKs) where input validation improves UX.

Look Elsewhere If:

  • You need real-time validation in JavaScript (use ajv or @apidevtools/json-schema instead).
  • Your use case is simple (e.g., validating a single field) and doesn’t justify the dependency.
  • You require Draft-3 support (limited compliance; consider alternatives like zendframework/zend-json-schema).
  • Your team lacks PHP expertise—this package requires understanding of JSON Schema syntax and PHP object handling.
  • You need high-performance validation at scale (e.g., 100K+ requests/sec); benchmark first—this library is accurate but not always the fastest (consider spatie/fractal or custom solutions for extreme scale).

How to Pitch It (Stakeholders)

For Executives:

"This package lets us automatically validate all JSON data entering our systems—APIs, configs, or internal tools—catching errors before they reach production. Think of it like a spellcheck for data: it ensures requests conform to our rules (e.g., 'age must be a number ≥ 18'), reducing bugs and support costs. It’s widely used (3.6K stars), actively maintained, and integrates seamlessly with our PHP stack. The upfront cost is minimal (a Composer install), but the payoff is fewer outages, happier developers, and cleaner data."

ROI:

  • DevOps: Fewer runtime errors → less fire-drill debugging.
  • Security: Blocks malformed input that could exploit edge cases.
  • Scalability: Early validation reduces load on downstream systems.

For Engineers:

"justinrainbow/json-schema is the gold standard for JSON Schema validation in PHP. Here’s why we should use it:

  1. Draft-7 Support: Future-proof for modern APIs (e.g., $dynamicRef, contentMediaType).
  2. Flexible Validation Modes:
    • Coerce types (CHECK_MODE_COERCE_TYPES) to auto-convert "true"bool or "17"int.
    • Apply defaults (CHECK_MODE_APPLY_DEFAULTS) to fill missing fields (e.g., processRefund: true if omitted).
    • Strict mode (CHECK_MODE_STRICT) for Draft-6 compliance.
  3. Performance: Optimized for most use cases (benchmark if validating millions of requests/sec).
  4. Integration-Friendly:
    • Works with Laravel (e.g., validate incoming requests in middleware).
    • Supports remote schemas (e.g., $ref: "https://api.example.com/schema.json").
  5. Debugging: Detailed error messages pinpoint exactly which field failed and why.

How We’d Use It:

  • API Layer: Validate all incoming requests (e.g., /users expects {"name": "string", "age": "integer"}).
  • CLI Tools: Ensure config files (e.g., config.json) match schemas before processing.
  • Data Pipelines: Validate JSON exports/imports to catch corruption early.

Alternatives? Only consider if we need Draft-3 or JavaScript-native validation. Otherwise, this is the most mature, maintained, and feature-complete option."*

Migration Path:

  • Start with basic validation in APIs (e.g., Laravel middleware).
  • Add type coercion for legacy systems handling loose input.
  • Expand to config validation and internal tools for broader impact.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata