symfony/json-streamer
Symfony JsonStreamer reads and writes data structures to and from JSON streams efficiently. Ideal for streaming large JSON payloads with low memory usage, integrating with Symfony Serializer to parse or generate JSON incrementally.
Response::stream() or spatie/json-encode may suffice, but JsonStreamer provides fine-grained control (e.g., null property inclusion, circular reference handling) and performance optimizations (cached readers/writers, memory leak fixes).Serializer, this adds ~10MB to dependencies. For teams using Laravel Serializer, a wrapper layer would be needed to bridge the two.JsonStreamer as a Laravel service, enabling dependency injection (e.g., JsonStreamer::createReader()).spatie/array-to-object or nesbot/carbon if they rely on Symfony’s Serializer. Conflict resolution required via priority binding or conditional loading.JsonStreamer handles self-referencing objects and union types (e.g., DateTime|string), but Laravel’s native JSON handling may not. Testing required for edge cases like:
Carbon, Uuid) requiring value transformers.json_encode() + chunking.Serializer? (Reduces integration effort)Serializer (reduces dependency bloat).HttpClient (for streaming API responses).API Platform (for GraphQL/REST streaming).Response::stream() or spatie/json-encode for simpler use cases.json_encode(), collect()->toJson()).composer require symfony/json-streamer ^8.0
Serializer, ensure version alignment (e.g., symfony/serializer:^6.4 for Laravel).// app/Providers/JsonStreamerServiceProvider.php
namespace App\Providers;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Encoder\JsonStreamEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Illuminate\Support\ServiceProvider;
class JsonStreamerServiceProvider extends ServiceProvider
{
public function register()
{
$encoders = [new JsonStreamEncoder()];
$normalizers = [new ObjectNormalizer()];
$this->app->singleton(SerializerInterface::class, fn() =>
new Serializer($normalizers, $encoders)
);
}
}
json_encode() with JsonStreamer for large payloads (e.g., exports).spatie/array-to-object or nesbot/carbon, ensure no duplicate Serializer bindings.Carbon):
$serializer->getConfiguration()->getNormalizers()->addSubscriber(new CarbonDateTimeSubscriber());
json_encode() + chunking.JsonStreamer is actively maintained (last release: 2026-03-31). Follow Symfony’s release cycle (major updates ~annually).TypeInfo configuration). Document common pitfalls (e.g., circular references).JsonStreamerFacade).json_encode() if streaming fails).How can I help you explore Laravel packages today?