PHPackages                             mr4-lc/php-json-exporter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mr4-lc/php-json-exporter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mr4-lc/php-json-exporter
========================

Export large datasets to a JSON file without memory exhaustion

0.0.1(2y ago)0311MITPHPPHP ^7.0|^8.0

Since Dec 19Pushed 2y agoCompare

[ Source](https://github.com/han48/mr4-lc.php-json-exporter)[ Packagist](https://packagist.org/packages/mr4-lc/php-json-exporter)[ RSS](/packages/mr4-lc-php-json-exporter/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (1)

JSON Exporter for PHP
=====================

[](#json-exporter-for-php)

> Why this library was created:
>
> At [Hyvor Talk](https://talk.hyvor.com), we have customers who have millions of comments on their websites, who want to export their data regularly to backup and analyze. Our first exporter was written to get all records from the database and create a JSON file from it, which took all data into memory. It worked for small websites, but larger websites could not use this as the server crashed due to memory exhaustion.So, we created this library to export data into a JSON file **in the disk** without taking it into the memory.

Fork: Support PHP 7.4

What you can do
---------------

[](#what-you-can-do)

The primary purpose of this library is to export large arrays of small objects (for example, table rows) into a JSON file in the disk. You can create a JSON file with multiple collections and direct values.

```
{
    "collection-1": [
        // an array of objects (rows)
        {},
        {},
        {}
    ],
    "collection-2": [
        {},
        {},
        {}
    ],
    "direct-value": "value"
}
```

Each object in a collection can be a representation of a row in a table of your database. The arrays are expected to be long (contains a lot of objects/rows).

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

[](#installation)

```
composer require mr4-lc/php-json-exporter
```

Usage
-----

[](#usage)

```
use Mr4Lc\JsonExporter\File;

$file = new File('export-file.json'); // you can use a relative or absolute path

// add a collection named users
$usersCollection = $file->collection('users');
$usersCollection->addItems(getUsers());
$usersCollection->addItems(getUsers(100));

// add a collection named
$postsCollection = $file->collection('posts');
$postsCollection->addItems(getPosts());
$postsCollection->addItems(getPosts(100));
$postsCollection->addItems(getPosts(200));

// add a direct value
// the value will be JSON encoded
// you can use arrays, objects, strings, numbers, booleans, null
$file->value('direct-value', 'value');
$file->value('direct-value-2', $myObject);
$file->value('json-value', '{"name": "John"}', encode: false); // the value will not be JSON encoded

// call this function finally
$file->end();
```

In the above example, `getUsers()` and `getPosts()` are hypothetical functions that returns a limited number of records (100) as an array, and they support an offset parameter to skip already added records. Usually, you would call the `addItems()` method inside a loop or callback (See Laravel example below). The JSON output of the above example will look like this:

```
{
    "users": [
        // array of JSON-encoded user objects
    ],
    "posts": [
        // array of JSON-encoded post objects
    ],

    "direct-value": "value",
    "direct-value-2": {
        // JSON-encoded object
    },
    "json-value": {"name": "John"}

}
```

Laravel Example for Collections
-------------------------------

[](#laravel-example-for-collections)

You can use [Laravel Chunking](https://laravel.com/docs/9.x/eloquent#chunking-results) to generate large collections.

```
use Mr4Lc\JsonExporter\File;

$file = new File('export-file.json');

$usersCollection = $file->collection('users');
User::chunk(200, fn ($users) => $usersCollection->addItems($users->toArray()));

$file->end();
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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

Unknown

Total

1

Last Release

927d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76fe5f5458078ee9ea3f07eb623d35e0d09540bcd83cfa688ff488739b0595f9?d=identicon)[Mr4](/maintainers/Mr4)

---

Top Contributors

[![supun-io](https://avatars.githubusercontent.com/u/44988673?v=4)](https://github.com/supun-io "supun-io (10 commits)")[![dungdv-sbt](https://avatars.githubusercontent.com/u/92131000?v=4)](https://github.com/dungdv-sbt "dungdv-sbt (1 commits)")[![han48](https://avatars.githubusercontent.com/u/27817127?v=4)](https://github.com/han48 "han48 (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mr4-lc-php-json-exporter/health.svg)

```
[![Health](https://phpackages.com/badges/mr4-lc-php-json-exporter/health.svg)](https://phpackages.com/packages/mr4-lc-php-json-exporter)
```

###  Alternatives

[friendsofsymfony/message

A framework-agnostic PHP 5.4+ user-to-user messaging library

6315.0k](/packages/friendsofsymfony-message)[tekintian/geo_utils

目前最全面的地理坐标转换工具，支持GPS坐标 WGS-84，百度坐标 BD-09，国测局 火星坐标GCJ-02之间的相互转换

3611.2k](/packages/tekintian-geo-utils)

PHPackages © 2026

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