salsify/json-streaming-parser
Streaming JSON parser for PHP that processes huge JSON documents without loading them into memory. SAX-style event callbacks via a Listener interface, PSR compliant, installable with Composer. Ideal for large files and low-memory environments.
json_decode().fopen) and HTTP streams (e.g., Guzzle’s StreamInterface), making it versatile for Laravel’s I/O needs.Listener classes for each use case (e.g., data extraction, validation). Risk of boilerplate code if overused; mitigate with base listener classes or Laravel service providers.ParsingException) must be mapped to Laravel’s exception handling (e.g., Reportable interfaces for logging).json_decode() for small payloads. Benchmark to justify adoption for small datasets.JsonToModelListener) or one-off implementations?EnsureJobRunsInOrder)?json_decode() with JSON_PARSE_BIGINT (for large ints)?StreamInterface to parse streaming API responses (e.g., paginated results).storage/app/json/large_file.json) via fopen.ParseLargeJsonJob) to avoid timeouts in HTTP requests.php artisan import:json) for bulk data processing.json_decode() call for a large payload with the streaming parser.$this->app->bind(ListenerInterface::class, function () {
return new YourCustomListener();
});
json_decode() calls in performance-critical code (e.g., API consumers).memory_get_usage() before/after).JsonToDatabaseListener).PositionAwareInterface) aids in pinpointing malformed JSON.setFilePosition()).ParsingException to include Laravel’s Reportable for structured logging.catch (ParsingException $e) {
report($e->withContext(['file_position' => $parser->getFilePosition()]));
}
README.| Failure Scenario | Mitigation Strategy | Laravel Integration |
|---|---|---|
| Malformed JSON | Validate schema with json_schema or custom rules. |
Use Laravel’s ValidatesWhen or FormRequest. |
| Stream corruption | Implement checksums or retry logic. | Laravel Queues’ retryAfter or maxAttempts. |
| Listener errors | Graceful degradation (e.g., skip invalid objects). | Log with Log::critical() and notify admins. |
| Resource exhaustion | Limit concurrent jobs or use smaller chunks. | Laravel Horizon for queue monitoring. |
json_decode()).How can I help you explore Laravel packages today?