Download the PHP package cerbero/lazy-json without Composer
On this page you can find all versions of the php package cerbero/lazy-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cerbero/lazy-json
More information about cerbero/lazy-json
Files in cerbero/lazy-json
Package lazy-json
Short Description Framework-agnostic package to load JSONs of any dimension and from any source into Laravel lazy collections.
License MIT
Homepage https://github.com/cerbero90/lazy-json
Informations about the package lazy-json
๐ผ Lazy JSON
Framework-agnostic package to load JSON of any size and from any source into Laravel lazy collections.
Lazy JSON recursively turns any JSON array or object into a lazy collection, consuming only a few KB of memory while parsing JSON of any dimension.
It optionally allows to extract only some sub-trees, instead of the whole JSON, with an easy dot-notation syntax.
Under the hood, ๐งฉ JSON Parser is used to parse JSONs and extract sub-trees.
Need to lazy load items from paginated JSON APIs? Consider using ๐ผ Lazy JSON Pages instead.
๐ฆ Install
Via Composer:
๐ฎ Usage
- ๐ฃ Basics
- ๐ง Sources
- ๐ฏ Dots
๐ฃ Basics
Depending on our coding style, we can call Lazy JSON in 3 different ways:
The variable $source
in our examples represents any Laravel lazy collection to process the JSON in a memory-efficient way:
๐ง Sources
A JSON source is any data point that provides a JSON. A wide range of sources are supported by default:
- strings, e.g.
{"foo":"bar"}
- iterables, i.e. arrays or instances of
Traversable
- file paths, e.g.
/path/to/large.json
- resources, e.g. streams
- API endpoint URLs, e.g.
https://endpoint.json
or any instance ofPsr\Http\Message\UriInterface
- PSR-7 requests, i.e. any instance of
Psr\Http\Message\RequestInterface
- PSR-7 messages, i.e. any instance of
Psr\Http\Message\MessageInterface
- PSR-7 streams, i.e. any instance of
Psr\Http\Message\StreamInterface
- Laravel HTTP client requests, i.e. any instance of
Illuminate\Http\Client\Request
- Laravel HTTP client responses, i.e. any instance of
Illuminate\Http\Client\Response
- user-defined sources, i.e. any instance of
Cerbero\JsonParser\Sources\Source
For more information about JSON sources, please consult the ๐งฉ JSON Parser documentation.
๐ฏ Dots
If we only need a sub-tree of a large JSON, we can use a simple dot-notation syntax to extract the desired path (or dot).
Consider this JSON for example. To extract only the cities and avoid parsing the rest of the JSON, we can set the results.*.location.city
dot:
The dot-notation syntax is very simple and it can include any of the following 4 elements:
- a key of a JSON array, e.g.
0
- a key of a JSON object, e.g.
results
- a dot to indicate the nesting level within a JSON, e.g.
results.0
- an asterisk to indicate all items within an array, e.g.
results.*
If we need to extract several sub-trees, Lazy JSON supports multiple dots:
๐ Change log
Please see CHANGELOG for more information on what has changed recently.
๐งช Testing
๐ Contributing
Please see CODE_OF_CONDUCT for details.
๐งฏ Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
๐ Credits
- Andrea Marco Sartori
- All Contributors
โ๏ธ License
The MIT License (MIT). Please see License File for more information.