PHPackages                             docteurklein/json-chunks - 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. docteurklein/json-chunks

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

docteurklein/json-chunks
========================

JSON encoder using generators to stream

1.0.1(7y ago)19122[1 PRs](https://github.com/docteurklein/json-chunks/pulls)MITPHP

Since Jun 5Pushed 7y ago2 watchersCompare

[ Source](https://github.com/docteurklein/json-chunks)[ Packagist](https://packagist.org/packages/docteurklein/json-chunks)[ RSS](/packages/docteurklein-json-chunks/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

json-chunks
===========

[](#json-chunks)

What ?
------

[](#what-)

A php library that allows to stream chunks of json documents.

How ?
-----

[](#how-)

It takes advantage of php generators and the native `json_encode` function.
To start streaming parts of a document, pass a function that `yield` serializable values.

> Note: You can nest multiple generators together.

### Example

[](#example)

```
$chunks = DocteurKlein\JsonChunks\Encode::from([
    '_links' => [
        'product' => function() {
            yield from [1, 2, 3];
        },
    ],
    '_embedded' => [
        'product' => function() {
            yield from [
                1,
                2,
                function() {
                    yield from [3];
                }
            ];
        },
    ],
]);

foreach ($chunks as $chunk) {
    echo $chunk;
}
```

> Note: more [examples](example) are available in the [specs](spec/EncodeSpec.php).

Tradeoffs
---------

[](#tradeoffs)

- This library won't try to pretty print the streamed content. It provides a `pretty` option for debug purposes, but that will buffer the whole output and thus won't stream anymore.
- Arrays containing both numeric and string indexes will be encoded to a json object or array depending on the type of the **first** key.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~99 days

Total

2

Last Release

2802d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1c31c81fac8f125314208689f18ddecd5f31ffb10b5485641158f3d438b6263?d=identicon)[florian.klein@free.fr](/maintainers/florian.klein@free.fr)

---

Top Contributors

[![docteurklein](https://avatars.githubusercontent.com/u/109846?v=4)](https://github.com/docteurklein "docteurklein (7 commits)")[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (1 commits)")

---

Tags

encodergenerator-functionjsonphpstreamyield

### Embed Badge

![Health badge](/badges/docteurklein-json-chunks/health.svg)

```
[![Health](https://phpackages.com/badges/docteurklein-json-chunks/health.svg)](https://phpackages.com/packages/docteurklein-json-chunks)
```

###  Alternatives

[formapro/pvm

The library provides us with a frame to build a workflow or a business process such as BPMN. Could execute tasks in parallel or delayed tasks

36723.8k](/packages/formapro-pvm)[nsavinov/nova-percent-field

A Laravel Nova field.

21276.3k](/packages/nsavinov-nova-percent-field)[zenstruck/redirect-bundle

Store redirects for your site and keeps statistics on redirects and 404 errors

2661.7k1](/packages/zenstruck-redirect-bundle)

PHPackages © 2026

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