PHPackages                             stolt/json-lines - 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. stolt/json-lines

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

stolt/json-lines
================

Library for the JSON Lines text file format.

v4.1.0(1y ago)40308.2k↓38.6%6[3 issues](https://github.com/raphaelstolt/json-lines/issues)1MITPHPPHP &gt;=8.0CI failing

Since Feb 25Pushed 1y ago4 watchersCompare

[ Source](https://github.com/raphaelstolt/json-lines)[ Packagist](https://packagist.org/packages/stolt/json-lines)[ RSS](/packages/stolt-json-lines/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (3)Versions (17)Used By (1)

JsonLines
=========

[](#jsonlines)

[![Test](https://github.com/raphaelstolt/json-lines/workflows/Test/badge.svg)](https://github.com/raphaelstolt/json-lines/workflows/Test/badge.svg)[![Version](https://camo.githubusercontent.com/b22a728b6ed1946dfbe5e55beebbc4b06b4c4b10d08e8fe6f0ea9f43abc9b895/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746f6c742f6a736f6e2d6c696e65732e7376673f7374796c653d666c6174)](https://packagist.org/packages/stolt/json-lines)[![PHP Version](https://camo.githubusercontent.com/e75ee3e54e01af4614fff6cca4b538e3da263832d751ee88abcf332c3174d3e5/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312b2d6666363962342e737667)](https://camo.githubusercontent.com/e75ee3e54e01af4614fff6cca4b538e3da263832d751ee88abcf332c3174d3e5/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312b2d6666363962342e737667)

This is a library to **enline** to the [JSON Lines](http://jsonlines.org/) format and to **deline** back from it to JSON.

#### Installation via Composer

[](#installation-via-composer)

```
composer require stolt/json-lines
```

#### Usage

[](#usage)

To **enline** a data structure into JSON Lines use the `enline` method.

```
$jsonLines = (new JsonLines())->enline([
    ["one" => 1, "two" => 2],
    ["three" => 3, "four" => 4, "five" => 5],
    ["six" => 6, "seven" => 7, "key" => "value"],
    ["nested" => ["a", "b", "c"]],
]);
var_dump($jsonLines);
```

Which will give you the following JSON Lines string.

```
string(107) "{"one":1,"two":2}
{"three":3,"four":4,"five":5}
{"six":6,"seven":7,"key":"value"}
{"nested":["a","b","c"]}
"

```

To **enline** a data structure into a JSON Lines file use the `enlineToFile` method, adding the `gz` extension will gzip compress the JSON Lines as shown next.

```
(new JsonLines())->enlineToFile([
    ["one" => 1, "two" => 2],
    ["three" => 3, "four" => 4, "five" => 5],
    ["six" => 6, "seven" => 7, "key" => "value"],
    ["nested" => ["a", "b", "c"]],
    'out.jsonl.gz'
]);
```

To **deline** JSON Lines back into JSON use the `deline` method.

```
$json = (new JsonLines())->deline('{"one":1,"two":2}
{"three":3,"four":4,"five":5}
{"six":6,"seven":7,"key":"value"}
{"nested":["a","b","c"]}'
);
var_dump($json)
```

Which will give you the following JSON string, which is *only* beautified here to illustrate the data structure.

```
string(287) "[
    {
        "one": 1,
        "two": 2
    },
    {
        "three": 3,
        "four": 4,
        "five": 5
    },
    {
        "six": 6,
        "seven": 7,
        "key": "value"
    },
    {
        "nested": [
            "a",
            "b",
            "c"
        ]
    }
]"

```

To **deline** a complete JSON Lines file back into JSON use the `delineFromFile` method.

```
$json = (new JsonLines())->delineFromFile('/path/to/enlined.jsonl');
```

To **deline** a complete JSON Lines file line-by-line, use the `delineEachLineFromFile` method. This allows to iterate over a large file without storing the entire delined file in memory.

```
$json_lines = (new JsonLines())->delineEachLineFromFile('/path/to/enlined.jsonl');
foreach ($json_lines as $json_line) {
    var_dump($json_line);
}
```

#### Running tests

[](#running-tests)

```
composer test
```

#### License

[](#license)

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

#### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more details.

#### Contributing

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for more details.

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 97.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 ~229 days

Recently: every ~349 days

Total

15

Last Release

570d ago

Major Versions

v0.2.1 → v1.0.02016-09-23

v1.0.0 → v2.0.02016-10-07

v2.1.0 → v3.0.02022-10-07

v3.0.0 → v4.0.02023-10-17

PHP version history (4 changes)v0.0.1PHP &gt;=5.6.16

v0.0.2PHP &gt;=5.5

v2.0.0PHP &gt;=5.6

v4.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/132faf5713fa951f4263fad02858a62e55c5d832ad775b33e49ba0cda2f2a028?d=identicon)[Raphael Stolt](/maintainers/Raphael%20Stolt)

---

Top Contributors

[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (70 commits)")[![joserick](https://avatars.githubusercontent.com/u/15143699?v=4)](https://github.com/joserick "joserick (1 commits)")[![lybrn](https://avatars.githubusercontent.com/u/78574116?v=4)](https://github.com/lybrn "lybrn (1 commits)")

---

Tags

jsonjsonlines

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/stolt-json-lines/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k334.7M785](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k504.8M165](/packages/mtdowling-jmespathphp)[jms/serializer

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

2.3k141.9M928](/packages/jms-serializer)[jms/serializer-bundle

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

1.8k92.4M680](/packages/jms-serializer-bundle)[clue/ndjson-react

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

15882.2M31](/packages/clue-ndjson-react)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30525.1M56](/packages/colinodell-json5)

PHPackages © 2026

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