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

braincrafted/json

Object-oriented wrapper around PHP’s json_encode() and json_decode() providing simple static encode/decode methods plus exception-based error handling. Supports decoding to arrays or objects via Json::DECODE_ASSOC and Json::DECODE_OBJECT.

View on GitHub
Deep Wiki
Context7

Object-orientated wrapper for json_encode() and json_decode() with error handling.

Frequently asked questions about Json
Is Braincrafted\Json still relevant for Laravel 9+ projects?
No, this package is outdated and redundant for Laravel 9+. Modern Laravel (5.5+) includes a built-in `Json` facade with similar functionality, and PHP 8.0+ provides native `JsonException` support. Use `Json::encode()` or `json_encode($data, JSON_THROW_ON_ERROR)` instead.
How do I install Braincrafted\Json in a Laravel project?
Run `composer require braincrafted/json:@stable` in your project root. Replace `@stable` with a specific version if needed. Note: This package is unmaintained and may conflict with modern Laravel or PHP versions. Test thoroughly before use.
Does this package support PHP 8.1+ and its JSON_THROW_ON_ERROR behavior?
No, this package predates PHP 8.1 and lacks support for `JSON_THROW_ON_ERROR`. In PHP 8.1+, native `json_encode()`/`json_decode()` with `JSON_THROW_ON_ERROR` already throws exceptions, making this wrapper unnecessary. Avoid using it in PHP 8.1+ environments.
Can I use Braincrafted\Json for API response serialization in Laravel?
Yes, but only if you’re on Laravel <5.5 or PHP 5.x. For Laravel 5.5+, use the built-in `Json::encode()` facade for consistency. The package’s error handling is useful in legacy systems where raw `json_encode()` errors are opaque, but it adds no value over Laravel’s native tools.
Will this package work with Laravel’s Eloquent models or API resources?
Technically yes, but it’s not recommended. Laravel’s `Json` facade or native `json_encode()` already handle Eloquent serialization seamlessly. This package won’t improve performance or add features like automatic resource formatting. Stick to Laravel’s defaults.
How does error handling differ from PHP’s native json_decode() in PHP 8.0+?
This package throws a custom `JsonDecodeException` on decode errors, while PHP 8.0+ uses `JsonException`. The behavior is similar, but mixing this package with native PHP 8.0+ functions could lead to inconsistent exception types. Prefer native `JsonException` in modern PHP.
Are there alternatives to Braincrafted\Json for Laravel projects?
Yes. For Laravel 5.5+, use the built-in `Json` facade. For PHP 8.0+, rely on native `json_encode()` with `JSON_THROW_ON_ERROR`. If you need advanced JSON features (e.g., validation), consider `json-schema` or Laravel’s `Illuminate/Validation`. This package is only useful for legacy systems.
Does this package support decoding JSON into associative arrays or objects?
Yes, use `Json::decode($json, Json::DECODE_ASSOC)` for arrays or `Json::DECODE_OBJECT` for objects. However, PHP 8.1+ defaults to throwing exceptions on decode errors, which this package doesn’t fully align with. Test thoroughly in mixed environments.
What are the risks of using this package in a production Laravel app?
The package is unmaintained (last update: 2014) and may break with modern PHP/Laravel versions. Risks include namespace conflicts, compatibility issues with PHP 8.0+ features, and lack of testing in real-world scenarios. Audit your codebase before adopting.
How do I migrate from Braincrafted\Json to Laravel’s built-in Json facade?
Replace `Json::encode($data)` with `Json::encode($data)` (same method name but Laravel’s facade) and `Json::decode($json)` with `Json::decode($json)`. Update error handling to catch `JsonException` instead of `JsonDecodeException`. Test all JSON-related paths, especially edge cases.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky