PHPackages                             maxakawizard/json-collection-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. maxakawizard/json-collection-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

maxakawizard/json-collection-parser
===================================

Streaming parser for large JSON files containing array of objects

1.10.1(1mo ago)134884.8k↓37.2%20[1 issues](https://github.com/MAXakaWIZARD/JsonCollectionParser/issues)9MITPHPPHP &gt;=7.1CI passing

Since Apr 29Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/MAXakaWIZARD/JsonCollectionParser)[ Packagist](https://packagist.org/packages/maxakawizard/json-collection-parser)[ Docs](https://github.com/MAXakaWIZARD/JsonCollectionParser)[ RSS](/packages/maxakawizard-json-collection-parser/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (10)Versions (21)Used By (9)

JsonCollectionParser
====================

[](#jsoncollectionparser)

[![Build](https://github.com/MAXakaWIZARD/JsonCollectionParser/actions/workflows/ci.yml/badge.svg)](https://github.com/MAXakaWIZARD/JsonCollectionParser/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b38c1af225dc25cf1ca00958bc9eaaadd0343a56b253f03310237c6f3684e0f9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d4158616b6157495a4152442f4a736f6e436f6c6c656374696f6e5061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MAXakaWIZARD/JsonCollectionParser/?branch=master)[![Code Climate](https://camo.githubusercontent.com/16bbe0aa0b1fb54615755f63ce583830218a634f5d4607ee867df43e9fc0190d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d4158616b6157495a4152442f4a736f6e436f6c6c656374696f6e5061727365722f6261646765732f6770612e737667)](https://codeclimate.com/github/MAXakaWIZARD/JsonCollectionParser)[![Coverage Status](https://camo.githubusercontent.com/0e71c9274e8fb48ff4095b6e96998593ae82464f1384dc73c4a55ce92d79be51/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4d4158616b6157495a4152442f4a736f6e436f6c6c656374696f6e5061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/MAXakaWIZARD/JsonCollectionParser?branch=master)

[![GitHub tag](https://camo.githubusercontent.com/1939ea460b672f117e19bfb386878059255cc6ffddf28966227922eda6af2bc0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f4d4158616b6157495a4152442f4a736f6e436f6c6c656374696f6e5061727365722e7376673f6c6162656c3d6c6174657374)](https://packagist.org/packages/maxakawizard/json-collection-parser)[![Packagist](https://camo.githubusercontent.com/d99752d3eaf3d1b444afb72211de97a55b8f5e417d76bdfa8d60a3bfbc5edfe6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6178616b6177697a6172642f6a736f6e2d636f6c6c656374696f6e2d7061727365722e737667)](https://packagist.org/packages/maxakawizard/json-collection-parser)[![Minimum PHP Version](https://camo.githubusercontent.com/be3b30c4ceb47b639794ebe0895f4fec6871dd53b2d7ae58d654a2018c3844fb/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/8100ab5387d20ffd982746e564de852634fda9994e128cf3e9e43b294faf32c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6178616b6177697a6172642f6a736f6e2d636f6c6c656374696f6e2d7061727365722e737667)](https://packagist.org/packages/maxakawizard/json-collection-parser)

Event-based parser for large JSON collections (consumes small amount of memory). Built on top of [JSON Streaming Parser](https://github.com/salsify/jsonstreamingparser)

This package is compliant with [PSR-4](https://www.php-fig.org/psr/psr-4/) and [PSR-12](https://www.php-fig.org/psr/psr-12/) code styles and supports parsing of [PSR-7](https://www.php-fig.org/psr/psr-7/) message interfaces. If you notice compliance oversights, please send a patch via pull request.

Installation
------------

[](#installation)

You will need [Composer](https://getcomposer.org/) to install the package

```
composer require maxakawizard/json-collection-parser:~1.0
```

Input data format
-----------------

[](#input-data-format)

Data must be in one of following formats:

### Array of objects (valid JSON)

[](#array-of-objects-valid-json)

```
[
    {
        "id": 78,
        "title": "Title",
        "dealType": "sale",
        "propertyType": "townhouse",
        "properties": {
            "bedroomsCount": 6,
            "parking": "yes"
        },
        "photos": [
            "1.jpg",
            "2.jpg"
        ],
        "agents": [
            {
                "name": "Joe",
                "email": "joe@realestate.email"
            },
            {
                "name": "Sally",
                "email": "sally@realestate.email"
            }
         ]
    },
    {
        "id": 729,
        "dealType": "rent_long",
        "propertyType": "villa"
    },
    {
        "id": 5165,
        "dealType": "rent_short",
        "propertyType": "villa"
    }
]
```

### Sequence of object literals:

[](#sequence-of-object-literals)

```
{
    "id": 78,
    "dealType": "sale",
    "propertyType": "townhouse"
}
{
    "id": 729,
    "dealType": "rent_long",
    "propertyType": "villa"
}
{
    "id": 5165,
    "dealType": "rent_short",
    "propertyType": "villa"
}

```

### Sequence of object and array literals:

[](#sequence-of-object-and-array-literals)

```
[[{
    "id": 78,
    "dealType": "sale",
    "propertyType": "townhouse"
}]]
{
    "id": 729,
    "dealType": "rent_long",
    "propertyType": "villa"
}
[{
    "id": 5165,
    "dealType": "rent_short",
    "propertyType": "villa"
}]

```

### Sequence of object and array literals (some of objects in subarrays, comma-separated):

[](#sequence-of-object-and-array-literals-some-of-objects-in-subarrays-comma-separated)

```
[
{
    "id": 78,
    "dealType": "sale",
    "propertyType": "townhouse"
},
{
    "id": 729,
    "dealType": "rent_long",
    "propertyType": "villa"
}
]
{
    "id": 5165,
    "dealType": "rent_short",
    "propertyType": "villa"
}

```

Usage
-----

[](#usage)

### Function as callback:

[](#function-as-callback)

```
function processItem(array $item)
{
    is_array($item); //true
    print_r($item);
}

$parser = new \JsonCollectionParser\Parser();
$parser->parse('/path/to/file.json', 'processItem');
```

### Closure as callback:

[](#closure-as-callback)

```
$items = [];

$parser = new \JsonCollectionParser\Parser();
$parser->parse('/path/to/file.json', function (array $item) use (&$items) {
    $items[] = $item;
});
```

### Static method as callback:

[](#static-method-as-callback)

```
class ItemProcessor {
    public static function process(array $item)
    {
        is_array($item); //true
        print_r($item);
    }
}

$parser = new \JsonCollectionParser\Parser();
$parser->parse('/path/to/file.json', ['ItemProcessor', 'process']);
```

### Instance method as callback:

[](#instance-method-as-callback)

```
class ItemProcessor {
    public function process(array $item)
    {
        is_array($item); //true
        print_r($item);
    }
}

$parser = new \JsonCollectionParser\Parser();
$processor = new \ItemProcessor();
$parser->parse('/path/to/file.json', [$processor, 'process']);
```

### Receive items as objects:

[](#receive-items-as-objects)

```
function processItem(\stdClass $item)
{
    is_array($item); //false
    is_object($item); //true
    print_r($item);
}

$parser = new \JsonCollectionParser\Parser();
$parser->parseAsObjects('/path/to/file.json', 'processItem');
```

### Receive chunks of items as arrays:

[](#receive-chunks-of-items-as-arrays)

```
function processChunk(array $chunk)
{
    is_array($chunk);    //true
    count($chunk) === 5; //true

    foreach ($chunk as $item) {
        is_array($item);  //true
        is_object($item); //false
        print_r($item);
    }
}

$parser = new \JsonCollectionParser\Parser();
$parser->chunk('/path/to/file.json', 'processChunk', 5);
```

### Receive chunks of items as objects:

[](#receive-chunks-of-items-as-objects)

```
function processChunk(array $chunk)
{
    is_array($chunk);    //true
    count($chunk) === 5; //true

    foreach ($chunk as $item) {
        is_array($item);  //false
        is_object($item); //true
        print_r($item);
    }
}

$parser = new \JsonCollectionParser\Parser();
$parser->chunkAsObjects('/path/to/file.json', 'processChunk', 5);
```

### Pass stream as parser input:

[](#pass-stream-as-parser-input)

```
$stream = fopen('/path/to/file.json', 'r');

$parser = new \JsonCollectionParser\Parser();
$parser->parseAsObjects($stream, 'processItem');
```

### Pass [PSR-7](https://www.php-fig.org/psr/psr-7/) MessageInterface as parser input:

[](#pass-psr-7-messageinterface-as-parser-input)

```
use Psr\Http\Message\MessageInterface;

/** @var MessageInterface $resource */
$resource = $httpClient->get('https://httpbin.org/get');

$parser = new \JsonCollectionParser\Parser();
$parser->parseAsObjects($resource, 'processItem');
```

### Pass [PSR-7](https://www.php-fig.org/psr/psr-7/) StreamInterface as parser input:

[](#pass-psr-7-streaminterface-as-parser-input)

```
use Psr\Http\Message\MessageInterface;

/** @var MessageInterface $resource */
$resource = $httpClient->get('https://httpbin.org/get');

$parser = new \JsonCollectionParser\Parser();
$parser->parseAsObjects($resource->getBody(), 'processItem');
```

Supported formats
-----------------

[](#supported-formats)

- `.json` - raw JSON
- `.gz` - GZIP-compressed JSON (you will need `zlib` PHP extension installed)

Supported sources
-----------------

[](#supported-sources)

- file
- string
- stream / resource
- HTTP message interface [PSR-7](https://www.php-fig.org/psr/psr-7/)

License
-------

[](#license)

This library is released under [MIT](http://www.tldrlegal.com/license/mit-license) license.

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance93

Actively maintained with recent releases

Popularity54

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 87.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~213 days

Recently: every ~485 days

Total

20

Last Release

31d ago

Major Versions

0.3.0 → 1.0.02016-03-23

PHP version history (5 changes)0.1.0PHP &gt;=5.3.0

1.0.0PHP ^5.4 | ^7.0

1.2.0PHP ^5.6 | ^7.0

1.3.0PHP ^7.1

1.8.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1138453?v=4)[Max Grigorian](/maintainers/MAXakaWIZARD)[@MAXakaWIZARD](https://github.com/MAXakaWIZARD)

---

Top Contributors

[![MAXakaWIZARD](https://avatars.githubusercontent.com/u/1138453?v=4)](https://github.com/MAXakaWIZARD "MAXakaWIZARD (64 commits)")[![jasonhebert](https://avatars.githubusercontent.com/u/4276690?v=4)](https://github.com/jasonhebert "jasonhebert (5 commits)")[![LiamBest](https://avatars.githubusercontent.com/u/489789?v=4)](https://github.com/LiamBest "LiamBest (3 commits)")[![peterpp](https://avatars.githubusercontent.com/u/1448883?v=4)](https://github.com/peterpp "peterpp (1 commits)")

---

Tags

json

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/maxakawizard-json-collection-parser/health.svg)

```
[![Health](https://phpackages.com/badges/maxakawizard-json-collection-parser/health.svg)](https://phpackages.com/packages/maxakawizard-json-collection-parser)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
