pcrov/jsonreader
A streaming, pull-based JSON parser for PHP. Process large documents incrementally from strings or streams without loading everything into memory. Iterate over tokens and events with a simple, readable API—ideal for big files and memory-constrained environments.
memory_limit." It replaces a bespoke parser, a jq subprocess, or a "just raise the limit / add more RAM" infrastructure workaround with a ~MIT-licensed Composer dependency.json_decode() would fatal or time out.json_decode failure.Adopt when most of these hold:
json_decode() gives, or you need to validate while reading.JsonStreamReader-style interface.Look elsewhere when:
json_decode() with JSON_THROW_ON_ERROR is faster (C vs. PHP), zero-dependency, and simpler. Do not add a parser to shave memory you do not need.opis/json, a JSONPath library, or a schema validator instead.halaxa/json-machine (streaming, much larger user base) and salsify/json-streaming-parser (event-based) are the mainstream comparisons. Benchmark all three against your real payloads before committing, and check the open-issue backlog, PHP 8.x coverage, and whether major versions have broken APIs historically.JSON_TABLE, Postgres jsonb operators, or a jq pipeline may solve the problem with no PHP dependency at all.To executives: We have a class of customer workflows — large imports, third-party data feeds, bulk exports — where our current approach either fails or forces us to buy bigger workers. A streaming JSON parser lets us process files far larger than memory in roughly constant footprint. That means we can ship the "large import" feature without a new service, without a queue-based re-architecture, and without raising infrastructure spend per tenant. It is a small MIT-licensed library: low cost, low lock-in, and we will isolate it behind our own interface so it is replaceable in days if needed. The main caveat is community size — this is a niche package, not a de facto standard — so the recommendation is adopt-with-a-wrapper, not adopt-everywhere.
To engineering: Event/token-based pull parser; you read() forward through the document and handle OBJECT_START, NAME, VALUE, ARRAY_END, and so on, so you never hold the full tree. Works from strings or streams, gives byte-offset error positions, and installs via Composer under MIT. Caveats to plan for: it is pure PHP, so it will not beat json_decode on small documents — use it only where memory or streaming actually matters; numeric values may surface as strings to preserve precision, so typed conversion is our code; and because we cannot assume long-term maintenance at this star count, we put it behind a thin adapter and add a benchmark/upgrade test so swapping to json-machine or salsify is a contained change. Ask: one spike against our real 200 MB+ payload to confirm memory ceiling and throughput before we commit it to the roadmap.
How can I help you explore Laravel packages today?