PHPackages                             indykoning/php-jsonl - 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. indykoning/php-jsonl

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

indykoning/php-jsonl
====================

PHP JSONL library for fast JSON Lines parsing and writing.

1.1.0(11mo ago)915.0k↓31%1MITPHPPHP ^8.1CI passing

Since Apr 5Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/indykoning/php-jsonl)[ Packagist](https://packagist.org/packages/indykoning/php-jsonl)[ Docs](https://github.com/indykoning/)[ Fund](https://www.paypal.me/indykoning)[ GitHub Sponsors](https://github.com/indykoning)[ RSS](/packages/indykoning-php-jsonl/feed)WikiDiscussions master Synced 1mo ago

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

PHP JsonL
=========

[](#php-jsonl)

This package implements the [JSON Lines](http://jsonlines.org/) format allowing you to encode and decode jsonl values. To take full advantage of the format we use [PHP's Generators](https://www.php.net/manual/en/language.generators.php)

#### Installation via Composer

[](#installation-via-composer)

```
composer require indykoning/php-jsonl
```

#### Usage

[](#usage)

##### Decoding

[](#decoding)

To decode jsonl you can use the `decode`:

```
\Indykoning\Jsonl\Jsonl::decode($jsonl, $associative);
```

The jsonl variable can be a string of jsonl lines, an array of jsonl lines, or any Traversable. So anything that can be iterated over and contains valid json can be passed.

If you want to decode the jsonl from a file, or decode it as you're downloading it you can use `decodeFromResource`

```
\Indykoning\Jsonl\Jsonl::decodeFromResource($resource, $associative);
```

Some examples you can use for this are:

```
$data = \Indykoning\Jsonl\Jsonl::decodeFromResource(fopen('/tmp/data.jsonl', 'r'), true);

$data = \Indykoning\Jsonl\Jsonl::decodeFromResource(
    \Illuminate\Support\Facades\Http::get('https://example.com/data.jsonl')->resource()
);
```

#### Encoding

[](#encoding)

Encoding can be done by calling `encode` with a Traversable or array with the objects inside

```
\Indykoning\Jsonl\Jsonl::encode($array);

\Indykoning\Jsonl\Jsonl::encode([
    ['name' => 'Gilbert', 'session' => '2013', 'score' => 24, 'completed' => true],
    ['name' => 'Alexa', 'session' => '2013', 'score' => 29, 'completed' => true],
]);
```

Encoding also supports writing directly to a resource using `encodeToResource`:

```
\Indykoning\Jsonl\Jsonl::encodeToResource($resource, $array);

\Indykoning\Jsonl\Jsonl::encodeToResource(
    fopen('/tmp/data.jsonl', 'w'),
    [
        ['name' => 'Gilbert', 'session' => '2013', 'score' => 24, 'completed' => true],
        ['name' => 'Alexa', 'session' => '2013', 'score' => 29, 'completed' => true],
    ]
);
```

#### Example using both

[](#example-using-both)

In practice this means you could proxy a theoretically infititely long file in json without issue.

```
function enrichData($data)
{
    foreach($data as $object)
    {
        $object->enriched_data = EnrichmentModel::find($object->id)->toArray();

        yield $object;
    }
}

response()->streamDownload(
    function () {
        $data = \Indykoning\Jsonl\Jsonl::decodeFromResource(
            \Illuminate\Support\Facades\Http::get('https://example.com/data.jsonl')->resource()
        );

        $data = enrichData($data);

        foreach(\Indykoning\Jsonl\Jsonl::encode($data) as $chunk) {
            echo $chunk;
            ob_flush();
            flush();
        }
    },
    'data.jsonl',
    [
        'Content-Type' => 'application/jsonl',
        'X-Accel-Buffering' => 'no'
    ]
);
```

With this code we'll be dealing with every json line one by one, enriching the data and passing it on to the client. When the client stops requesting data we will stop requesting and enriching data.

#### Why not package X or Y instead?

[](#why-not-package-x-or-y-instead)

I haven't found any php Json Lines package that deals with JSON Lines in a natural and efficient way. Either relying on files to encode/decode JSON. Or loading the entire File or data into memory first, which is a problem for big data.

This package allows extremely simple encoding/decoding, taking advantage of streaming and generators to reduce memory footprint.

#### Running tests

[](#running-tests)

```
composer test
```

#### License

[](#license)

This library is licensed under the MIT license. Please see [LICENSE](LICENSE) for more details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance51

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~30 days

Total

3

Last Release

347d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9397dc2c1f918c7c283295d3aea68467378cd92bc406383316d5830b38aff683?d=identicon)[indykoning](/maintainers/indykoning)

---

Top Contributors

[![indykoning](https://avatars.githubusercontent.com/u/15870933?v=4)](https://github.com/indykoning "indykoning (8 commits)")

---

Tags

phpjsonjsonlinesNDJSONjsonlJSON LinesldjsonNewline delimited JSONLine delimited JSON

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/indykoning-php-jsonl/health.svg)

```
[![Health](https://phpackages.com/badges/indykoning-php-jsonl/health.svg)](https://phpackages.com/packages/indykoning-php-jsonl)
```

###  Alternatives

[clue/ndjson-react

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

15267.7M16](/packages/clue-ndjson-react)[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

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