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 4w 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 61% 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

2892d 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

[ether/seo

SEO utilities including a unique field type, sitemap, &amp; redirect manager

296468.7k15](/packages/ether-seo)[crazycodr/standard-exceptions

This project is aimed at providing additional standard exceptions to php. Many exceptions that are missing from the SPL are constantly being reproduced in different projects. By providing a package of high-quality, well organised exceptions, it will, in the long run, increase interoperability between projects.

146235.3k7](/packages/crazycodr-standard-exceptions)[elgentos/serversideanalytics2

Elgentos\_ServerSideAnalytics for magento 2

70103.4k](/packages/elgentos-serversideanalytics2)[tomatophp/filament-settings-hub

Manage your Filament app settings with GUI and helpers

5858.8k9](/packages/tomatophp-filament-settings-hub)[payload-interop/payload-interop

An interoperable Domain Payload Object specification.

3892.7k7](/packages/payload-interop-payload-interop)[laravel-frontend-presets/inertiajs

A Laravel frontend preset to get you up and running with Inertia.js

1454.5k](/packages/laravel-frontend-presets-inertiajs)

PHPackages © 2026

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