bcncommerce/json-stream
Stream JSON reading and writing for PHP. Incrementally parse or generate large JSON documents from file handles without loading everything into memory. Supports entering/leaving objects and arrays, reading keys or iterating items—ideal for exports/imports like product catalogs.
Storage facade for generating/parsing JSON files in S3, local storage, or database blobs.json_encode() for large responses (e.g., paginated data, chunked transfers) without blocking.Illuminate\Queue system.enter()/leave()/write() API is straightforward to adopt, requiring minimal refactoring of existing Laravel codebases.JsonSerializable for complex nested structures (e.g., Eloquent models with circular references).json_encode()/json_decode() suffice for small payloads, this package is essential for scalability (e.g., >100MB files) and performance-critical paths.league/json-stream (more active, similar API).enter()/leave() calls). Benchmark against json_encode() for small payloads to justify adoption.Handler for consistent logging and monitoring.null handling).Jsonable or JsonSerializable interfaces.Jsonable) or symfony/serializer address the need without streaming?league/json-stream (more stars, recent updates) or spatie/array-to-xml for hybrid use cases.json_encode()?json_encode(file_get_contents()) with Writer for large file exports via Storage::disk()->write().Writer to generate chunked JSON responses (e.g., response()->stream()).handle() methods (e.g., parsing uploads, webhooks).JsonSerializable for models with complex JSON attributes.json_encode() in exports for memory efficiency.DB::table()->insert() with chunked data).Writer for a non-critical bulk export (e.g., admin panel CSV/JSON export).json_encode().composer.json and publish config (if needed).JsonStream::export()).// app/Services/JsonStreamService.php
public function exportCatalog(array $catalog, string $path) {
$fh = Storage::disk('public')->open($path, 'w');
$writer = new \Bcncommerce\JsonStream\Writer($fh);
$writer->enter(\Bcncommerce\JsonStream\Writer::TYPE_OBJECT);
$writer->write('catalog', $catalog['id']);
$writer->enter('items', \Bcncommerce\JsonStream\Writer::TYPE_ARRAY);
foreach ($catalog['products'] as $product) {
$writer->write(null, $product);
}
$writer->leave();
$writer->leave();
fclose($fh);
}
response()->json() for large endpoints (e.g., /api/exports).StreamJsonResponse middleware).Reader in queue jobs (e.g., parsing uploads, webhooks).Illuminate\Bus\Queueable and ShouldQueue.ext-json (enabled by default in Laravel).null vs. mixed in read()).guzzlehttp/guzzle, spatie/laravel-permission).json namespace usage.php artisan export:catalog).json_encode() in controllers/views with Writer incrementally.Reader for parsing.composer.json (e.g., ^1.0) to avoid breaking changes.league/json-stream).league/json-stream (similar API).How can I help you explore Laravel packages today?