Andrea Marco Sartori dcb39ff7b6 Update README
2023-01-12 21:22:34 +10:00
2023-01-11 15:35:58 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2022-09-15 23:37:30 +02:00
2022-09-16 07:17:51 +10:00
2022-09-15 23:37:30 +02:00
2023-01-04 16:51:20 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2022-09-15 23:37:30 +02:00
2022-12-29 21:32:35 +10:00
2022-09-16 07:17:51 +10:00
2022-09-16 07:17:51 +10:00
2023-01-12 21:22:34 +10:00

🧩 JSON Parser

Author PHP Version Build Status Coverage Status Quality Score PHPStan Level Latest Version Software License PSR-7 PSR-12 Total Downloads

Zero-dependencies pull parser to read large JSON from any source in a memory-efficient way.

📦 Install

Via Composer:

composer require cerbero/json-parser

🔮 Usage

JSON Parser provides a minimal API to read large JSON from any source:

use Cerbero\JsonParser\JsonParser;

// the JSON source in this example is an API endpoint
$source = 'https://randomuser.me/api/1.4?seed=json-parser&results=5';

foreach (new JsonParser($source) as $key => $value) {
    // instead of loading the whole JSON, we keep in memory only one key and value at a time
}

Depending on our taste, we can instantiate the parser in 3 different ways:

use Cerbero\JsonParser\JsonParser;

// classic object instantiation
new JsonParser($source);

// static instantiation, facilitates methods chaining
JsonParser::parse($source);

// namespaced function
use function Cerbero\JsonParser\parseJson;

parseJson($source);

Sources

A wide range of JSON sources is supported, here is the full list:

  • strings, e.g. {"foo":"bar"}
  • iterables, i.e. arrays or instances of Traversable
  • files, e.g. /path/to/large_file.json
  • resources, e.g. streams
  • API endpoint URLs, e.g. https://endpoint.json or any instance of Psr\Http\Message\UriInterface
  • PSR-7 compliant requests, i.e. any instance of Psr\Http\Message\RequestInterface
  • PSR-7 compliant messages, i.e. any instance of Psr\Http\Message\MessageInterface
  • PSR-7 compliant streams, i.e. any instance of Psr\Http\Message\StreamInterface
  • responses from the Laravel HTTP client, i.e. any instance of Illuminate\Http\Client\Response
  • user-defined sources, i.e. any instance of Cerbero\JsonParser\Sources\Source

📆 Change log

Please see CHANGELOG for more information on what has changed recently.

🧪 Testing

composer test

💞 Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

🧯 Security

If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.

🏅 Credits

⚖️ License

The MIT License (MIT). Please see License File for more information.

Description
🧩 Zero-dependencies pull parser to read large JSON from any source in a memory-efficient way.
Readme 364 KiB
Languages
PHP 100%