A memory-efficient PHP stream parser for large JSON files and streams, enabling iteration without loading entire documents.
JSON Machine is a PHP library designed for parsing large JSON files or streams incrementally, using generators to yield items one by one. It solves the problem of memory exhaustion when processing multi-gigabyte JSON documents by avoiding loading the entire structure into memory at once.
PHP developers working with large JSON datasets from APIs, files, or streams, such as those processing big data exports, log files, or API responses that exceed memory limits.
Developers choose JSON Machine for its constant memory footprint, simple iterator-based API, and support for JSON Pointer to target specific document sections, making it a robust alternative to `json_decode` for unpredictable or massive JSON inputs.
Efficient, easy-to-use, and fast PHP JSON stream parser
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Processes JSON items one at a time using generators, ensuring memory footprint remains low even for multi-gigabyte files, as demonstrated in the TL;DR comparison with json_decode.
Replaces json_decode with a foreach-loop interface, making it easy to integrate into existing code without learning event-driven callbacks.
Supports JSON Pointer syntax to iterate specific subtrees or scalar values, allowing efficient parsing without loading unnecessary parts of the document.
Offers ErrorWrappingDecoder to skip malformed items by wrapping errors in DecodingError objects, preventing total failure due to single bad entries.
Works seamlessly with HTTP clients like Guzzle and Symfony HttpClient for parsing real-time JSON API responses, with examples provided in the README.
Cannot directly access items by index or key; requires full iteration or JSON Pointer lookups, which is inefficient for scenarios needing quick element retrieval.
RecursiveItems is notably slower than Items for deeply nested structures, as admitted in the README, impacting performance for complex JSON layouts.
Enabling debug for progress tracking adds performance cost, and getPosition() returns 0 when disabled, limiting progress monitoring without trade-offs.
Default ExtJsonDecoder requires PHP's ext-json; without it, custom decoders must be implemented, adding complexity for environments lacking this extension.