dragon-code/laravel-json-response
A Laravel package for building consistent JSON API responses. It provides fluent helpers for success, error, and custom payloads, helping standardize response structure and reduce boilerplate across controllers and APIs.
Accept: application/json before routing, or a ForceJsonResponse middleware). The PM decision remains "build in-house," not "adopt a dependency" — a Laravel 13 compatibility PR does not change the size of the code we would be replacing.problem+json, and generated client SDKs — but it does not belong on a roadmap as its own line.Consider the pattern when:
api route group must never leak HTML to a client.Accept headers — mobile HTTP libraries, curl scripts, third-party webhooks — and you want deterministic JSON regardless.application/json.Consider this package still essentially never:
composer.json platform constraint should be verified before assuming 3.2.0 covers your Laravel version; a compatibility bump is not the same as a tested support matrix.problem+json error bodies, per-endpoint error codes, localized error messages, dual HTML/JSON rendering, or normalization of status codes and exception payloads.To executives: The capability is worth having — every API client gets consistent JSON errors instead of HTML pages, which reduces integration support load. But we should not take a dependency here. Release 3.2.0 shows the project is not abandoned (a contributor added Laravel 13 support), which is a genuinely better signal than "archived," yet it is still a near-zero-adoption repo with no support commitment and nothing in the release beyond a compatibility bump and bot housekeeping. This remains a weekend-sized middleware we own: adopting it trades a small convenience for a permanent maintenance question mark on our response path, and buys us no vendor relationship or roadmap influence.
To engineering: Implement a ForceJsonResponse middleware that sets Accept: application/json on api-group requests, register it on the api group, and add two feature tests: a 404 on an api route returns JSON, and a validation failure returns JSON. That is functionally equivalent to this package for our needs, keeps us in control of the error envelope, and avoids pinning a Laravel version to a repo maintained by sporadic volunteer PRs. Note that 3.2.0's Laravel 13 claim should be treated as "not broken on 13" rather than "supported on 13." Revisit only if requirements grow to full content negotiation — and in that case choose a maintained library, not this one.
How can I help you explore Laravel packages today?