PHPackages                             sunaoka/ndjson - 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. sunaoka/ndjson

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

sunaoka/ndjson
==============

A PHP library to read and write NDJSON (Newline Delimited JSON)

1.1.7(4mo ago)952.9k—3.1%3MITPHPPHP ^5.5 || ^7.0 || ^8.0CI passing

Since Jul 8Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/sunaoka/ndjson)[ Packagist](https://packagist.org/packages/sunaoka/ndjson)[ RSS](/packages/sunaoka-ndjson/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (16)Used By (0)

NDJSON Reader/Writer for PHP
============================

[](#ndjson-readerwriter-for-php)

[![Latest](https://camo.githubusercontent.com/8c89d5ae33053b2c9fa3a18854030c00bb42b1d3fbf5898bdc5a0377c05733d4/68747470733a2f2f706f7365722e707567782e6f72672f73756e616f6b612f6e646a736f6e2f76)](https://packagist.org/packages/sunaoka/ndjson)[![License](https://camo.githubusercontent.com/02e8ec13e17b8c8048c63af624a61b4fc2b32e58f3733dd490254e2823d26c44/68747470733a2f2f706f7365722e707567782e6f72672f73756e616f6b612f6e646a736f6e2f6c6963656e7365)](https://packagist.org/packages/sunaoka/ndjson)[![PHP](https://camo.githubusercontent.com/0906b01f9a22b4c5a01497a38a0fa8acaf31844377d6496fcd2e8975f1e3936d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73756e616f6b612f6e646a736f6e)](composer.json)[![Test](https://github.com/sunaoka/ndjson/actions/workflows/test.yml/badge.svg)](https://github.com/sunaoka/ndjson/actions/workflows/test.yml)[![codecov](https://camo.githubusercontent.com/3a4f20a0580d38330f79c898cc0dbb2ecf2a2c3ca856ebcbfa8e6810b1d8d3ae/68747470733a2f2f636f6465636f762e696f2f67682f73756e616f6b612f6e646a736f6e2f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/sunaoka/ndjson)

---

A PHP library to read and write [NDJSON](https://github.com/ndjson) (Newline Delimited JSON).

Read and write one line at a time to execute with low memory usage.

For better performance, you can also read and write on multiple lines.

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

[](#installation)

```
composer require sunaoka/ndjson
```

Usage
-----

[](#usage)

### Read

[](#read)

#### Example NDJSON

[](#example-ndjson)

```
{"test": "001"}
{"test": "002"}
{"test": "003"}
{"test": "004"}
{"test": "005"}
```

#### Read one line at a time

[](#read-one-line-at-a-time)

```
use Sunaoka\Ndjson\NDJSON;

$ndjson = new NDJSON('/path/to/file.ndjson');

while ($json = $ndjson->readline()) {
    var_dump($json);
}
```

```
array(1) {
  ["test"]=>
  string(3) "001"
}
array(1) {
  ["test"]=>
  string(3) "002"
}
array(1) {
  ["test"]=>
  string(3) "003"
}
array(1) {
  ["test"]=>
  string(3) "004"
}
array(1) {
  ["test"]=>
  string(3) "005"
}

```

#### Read 3 lines at a time

[](#read-3-lines-at-a-time)

```
use Sunaoka\Ndjson\NDJSON;

$ndjson = new NDJSON('/path/to/file.ndjson');

foreach ($ndjson->readlines(3) as $jsons) {
    var_dump($jsons);
}
```

```
array(3) {
  [0]=>
  array(1) {
    ["test"]=>
    string(3) "001"
  }
  [1]=>
  array(1) {
    ["test"]=>
    string(3) "002"
  }
  [2]=>
  array(1) {
    ["test"]=>
    string(3) "003"
  }
}
array(2) {
  [0]=>
  array(1) {
    ["test"]=>
    string(3) "004"
  }
  [1]=>
  array(1) {
    ["test"]=>
    string(3) "005"
  }
}

```

### Write

[](#write)

#### Write one line at a time

[](#write-one-line-at-a-time)

```
use Sunaoka\Ndjson\NDJSON;

$ndjson = new NDJSON('/path/to/file.ndjson');
$ndjson->writeline(['test' => '001']);
$ndjson->writeline(['test' => '002']);
```

```
{"test": "001"}
{"test": "002"}

```

#### Write multiple lines at a time

[](#write-multiple-lines-at-a-time)

```
use Sunaoka\Ndjson\NDJSON;

$ndjson = new NDJSON('/path/to/file.ndjson');
$ndjson->writelines([['test' => '001'], ['test' => '002']]);
```

```
{"test": "001"}
{"test": "002"}

```

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance74

Regular maintenance activity

Popularity38

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~97 days

Recently: every ~218 days

Total

14

Last Release

141d ago

Major Versions

0.1.4 → 1.0.02022-08-01

PHP version history (3 changes)0.1.0PHP ^5.5 | ^5.6 | ^7.0 | ^7.1 | ^7.2 | ^7.3 | ^7.4 | ^8.0 | ^8.1 | ^8.2

0.1.2PHP &gt;=5.5

1.1.2PHP ^5.5 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/aab0eef8c17cb4a1d856c457224642bdf29adf5255e2f9db84e1c192f78ef272?d=identicon)[sunaoka](/maintainers/sunaoka)

---

Top Contributors

[![sunaoka](https://avatars.githubusercontent.com/u/105845?v=4)](https://github.com/sunaoka "sunaoka (48 commits)")

---

Tags

ndjsonphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sunaoka-ndjson/health.svg)

```
[![Health](https://phpackages.com/badges/sunaoka-ndjson/health.svg)](https://phpackages.com/packages/sunaoka-ndjson)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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