Weave 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 Laravel Package

ergebnis/json

ergebnis/json provides a Json value object for representing a valid JSON string. Create instances from strings or files, with clear exceptions for invalid JSON, missing or unreadable files. Ideal for safely handling JSON input in PHP applications.

View on GitHub
Deep Wiki
Context7

📃 Provides a composer package with a Json value object for representing a valid JSON string.

Frequently asked questions about Json
What is ergebnis/json and how does it help with JSON in Laravel?
ergebnis/json is a framework-agnostic Composer package that provides a Json value object for representing a valid JSON string. In Laravel, it gives you a typed, immutable object you can pass around after validating JSON from strings or files instead of relying on raw strings or loose arrays. It throws clear exceptions when JSON is invalid or files are missing or unreadable.
How do I install ergebnis/json in a Laravel application?
Run composer require ergebnis/json in your Laravel project root. Because it is a plain Composer package with no service provider, there is nothing to register or configure. You can start using Ergebnis\Json\Json immediately in your application code.
Does ergebnis/json support all Laravel versions?
It is not tied to Laravel, so it works with any Laravel version as long as your project's PHP version satisfies the package requirements. Check the package's composer.json or Packagist page for the supported PHP versions. Laravel's own version is largely irrelevant because the package has no Laravel-specific dependencies.
How do I create a Json value object from a string in Laravel?
Call Json::fromString($encoded) with the JSON string you want to validate. If the string is valid JSON, you get a Json instance; if not, a Json\Exception\NotJson exception is thrown. This is useful at request or service boundaries where you want to fail fast on malformed JSON.
Can I create a Json object from a JSON file with ergebnis/json?
Yes, use Json::fromFile($path). It throws FileDoesNotExist if the file is missing, FileCanNotBeRead if it is unreadable, and FileDoesNotContainJson if the contents are not valid JSON. On success you receive a Json value object representing the file contents.
What exceptions does ergebnis/json throw for invalid JSON input?
The package defines exceptions such as Json\Exception\NotJson for invalid JSON strings, plus FileDoesNotExist, FileCanNotBeRead, and FileDoesNotContainJson for file-based input. These exceptions make error handling explicit and easy to catch in Laravel controllers or services. You can catch them and return appropriate HTTP responses or log messages.
Is ergebnis/json a replacement for Laravel's built-in JSON handling?
Not exactly; Laravel already offers convenient JSON handling through methods like request()->json() and json_decode(). ergebnis/json is better viewed as a small value object for strict validation and type safety when you want to guarantee a string contains valid JSON before passing it around. You can use it alongside Laravel's helpers rather than replacing them.
How can I validate JSON request payloads with ergebnis/json in Laravel?
Extract the raw payload, for example with $request->getContent(), then pass it to Json::fromString(). If validation fails, catch Json\Exception\NotJson and return a 422 response. This adds a strict JSON validity check before you decode or persist the payload.
How do I test code that uses ergebnis/json?
Write unit tests that call Json::fromString() or Json::fromFile() with valid and invalid samples and assert the returned instance or the expected exception. Data providers work well for covering malformed JSON, missing files, and unreadable files. Because the value object has no Laravel dependencies, tests run quickly without booting the framework.
Is ergebnis/json suitable for production and actively maintained?
It is a small, focused package with a clear purpose and automated workflows for integration, release, and code coverage, as shown by its repository badges. For production, its main value is strict JSON validation with predictable exceptions and no framework coupling. Review its release activity and PHP version support on Packagist to confirm it fits your maintenance policy.
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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel