PHPackages                             p1ratrulezzz/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. p1ratrulezzz/json-collection-parser

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

p1ratrulezzz/json-collection-parser
===================================

Streaming parser for large JSON files containing array of objects

1.5.4(7y ago)03.0kMITPHPPHP ^7.1

Since Apr 29Pushed 6y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (3)Versions (18)Used By (0)

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

[](#jsoncollectionparser)

[![Build Status](https://camo.githubusercontent.com/00761c3bf34dbdddb19c1d91e3eef7b315ccac645783bb9efed60fbff9dbff8e/68747470733a2f2f7472617669732d63692e6f72672f703172617472756c657a7a7a2f4a736f6e436f6c6c656374696f6e5061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/p1ratrulezzz/JsonCollectionParser)

[![Latest Stable Version](https://camo.githubusercontent.com/351f44c3659153d9c1c5023d6f05e1c871aa330d72ecc0ebd5f8cde3fecbd362/68747470733a2f2f706f7365722e707567782e6f72672f703172617472756c657a7a7a2f6a736f6e2d636f6c6c656374696f6e2d7061727365722f762f737461626c65)](https://packagist.org/packages/p1ratrulezzz/json-collection-parser)[![Total Downloads](https://camo.githubusercontent.com/469dd0eafe9c8be801a12c7167ed096b786e9ac5577fd28c2d638eaf51d85d9d/68747470733a2f2f706f7365722e707567782e6f72672f703172617472756c657a7a7a2f6a736f6e2d636f6c6c656374696f6e2d7061727365722f646f776e6c6f616473)](https://packagist.org/packages/p1ratrulezzz/json-collection-parser)[![composer.lock](https://camo.githubusercontent.com/029abd8d960970be00f784b9884dcbaf1a29e493a77e51d4c433bc8ed73808d8/68747470733a2f2f706f7365722e707567782e6f72672f703172617472756c657a7a7a2f6a736f6e2d636f6c6c656374696f6e2d7061727365722f636f6d706f7365726c6f636b)](https://packagist.org/packages/p1ratrulezzz/json-collection-parser)[![Minimum PHP Version](https://camo.githubusercontent.com/be3b30c4ceb47b639794ebe0895f4fec6871dd53b2d7ae58d654a2018c3844fb/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e737667)](https://php.net/)

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](http://www.php-fig.org/psr/4/), [PSR-1](http://www.php-fig.org/psr/1/), and [PSR-2](http://www.php-fig.org/psr/2/). 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 p1ratrulezzz/json-collection-parser ~1.5
```

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

[](#input-data-format)

Collection must be an array of objects.

```
[
    {
        "id": 78,
        "title": "Title",
        "dealType": "sale",
        "propertyType": "townhouse",
        "properties": {
            "bedroomsCount": 6,
            "parking": "yes"
        },
        "photos": [
            "1.jpg",
            "2.jpg"
        ]
    },
    {
        "id": 729,
        "dealType": "rent_long",
        "propertyType": "villa"
    },
    {
        "id": 5165,
        "dealType": "rent_short",
        "propertyType": "villa"
    }
]
```

Usage
-----

[](#usage)

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:

```
$items = [];

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

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:

```
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:

```
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');
```

Pass stream as parser input:

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

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

Supported file formats
----------------------

[](#supported-file-formats)

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

Running tests
-------------

[](#running-tests)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 62.2% 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 ~93 days

Recently: every ~22 days

Total

17

Last Release

2532d ago

Major Versions

0.3.0 → 1.0.02016-03-23

PHP version history (4 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

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdee86c889de97363d62013d855a7ec155f0660fb729bd34400dc3f6c7cc14e4?d=identicon)[p1ratrulezzz](/maintainers/p1ratrulezzz)

---

Top Contributors

[![MAXakaWIZARD](https://avatars.githubusercontent.com/u/1138453?v=4)](https://github.com/MAXakaWIZARD "MAXakaWIZARD (28 commits)")[![p1ratrulezzz](https://avatars.githubusercontent.com/u/5019669?v=4)](https://github.com/p1ratrulezzz "p1ratrulezzz (16 commits)")[![peterpp](https://avatars.githubusercontent.com/u/1448883?v=4)](https://github.com/peterpp "peterpp (1 commits)")

---

Tags

json

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M609](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M849](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M622](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15267.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

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