PHPackages                             clue/json-stream - 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. clue/json-stream

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

clue/json-stream
================

Lightweight incremental streaming JSON parser

v0.1.1(5y ago)24238.8k↓76.4%5[2 issues](https://github.com/clue/json-stream/issues)3MITPHPPHP &gt;=5.3CI failing

Since Mar 10Pushed 4y ago3 watchersCompare

[ Source](https://github.com/clue/json-stream)[ Packagist](https://packagist.org/packages/clue/json-stream)[ Docs](https://github.com/clue/json-stream)[ Fund](https://clue.engineering/support)[ GitHub Sponsors](https://github.com/clue)[ RSS](/packages/clue-json-stream/feed)WikiDiscussions master Synced 2d ago

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

clue/json-stream
================

[](#cluejson-stream)

[![CI status](https://github.com/clue/json-stream/workflows/CI/badge.svg)](https://github.com/clue/json-stream/actions)[![installs on Packagist](https://camo.githubusercontent.com/d344599666759df53d402c9b25d978f86df17988cc16a0797bd383a9d3f11b9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c75652f6a736f6e2d73747265616d3f636f6c6f723d626c7565266c6162656c3d696e7374616c6c732532306f6e2532305061636b6167697374)](https://packagist.org/packages/clue/json-stream)

A really simple and lightweight, incremental parser for [JSON streaming](https://en.wikipedia.org/wiki/JSON_Streaming)(concatenated JSON and [newline-delimited JSON](http://ndjson.org/), in PHP. You can use this library to process a stream of data that consists of multiple JSON documents.

**Table of contents**

- [Support us](#support-us)
- [JSON streaming](#json-streaming)
- [Quickstart example](#quickstart-example)
- [Description](#description)
- [Install](#install)
- [Tests](#tests)
- [License](#license)
- [More](#more)

Support us
----------

[](#support-us)

We invest a lot of time developing, maintaining and updating our awesome open-source projects. You can help us sustain this high-quality of our work by [becoming a sponsor on GitHub](https://github.com/sponsors/clue). Sponsors get numerous benefits in return, see our [sponsoring page](https://github.com/sponsors/clue)for details.

Let's take these projects to the next level together! 🚀

JSON streaming
--------------

[](#json-streaming)

A newline-delimited JSON (NDJSON) example stream consisting of 3 individual JSON documents could look like this:

```
{ "id": 1, "name": "first" }
{ "id": 3, "name": "third" }
{ "id": 6, "name": "sixth" }
```

> Less commonly, the same format is referred to as JSON lines (JSONL) or line-delimited JSON (LDJSON), which is not to be confused with JSON-LD. To avoid confusion, we consistently refer to this as newline-delimited JSON (NDJSON). If you control the generating side, we highly recommend going for NDJSON instead of using concatenated JSON as discussed below. See also [clue/reactphp-ndjson](https://github.com/clue/reactphp-ndjson).

For this project, the whitespace between the individual JSON documents is entirely optional. Instead of newlines, you can use any number of whitespace or none at all.

A concatenated JSON example stream consisting of 3 individual JSON documents could look like this:

```
{ "id": 1, "name": "first" }{ "id": 3, "name": "third" }{ "id": 6, "name": "sixth"}
```

The input stream can be of arbitrary size and can be interrupted at any time. This is often useful for processing network streams, where the chunk/buffer size is not under your control and you could potentially read single bytes only.

Please note that this library is about processing a stream that can contain any number of JSON documents. It is assumed that each document has a reasonable size and fits into memory. This is not to be confused with a streaming parser for processing a single, huge JSON document that is too big to fit into memory.

Quickstart example
------------------

[](#quickstart-example)

Once [installed](#install), you can use the following sample code to parse a stream of JSON chunks:

```
$parser = new StreamingJsonParser();

assert($parser->push('[ 1, 2') === array());
assert($parser->push('3 ]') === array(array(1, 2, 3));
assert($parser->push('{} {}') === array(array(), array());
```

Description
-----------

[](#description)

This is actually only a really simple hack to call a normal document based parser whenever it *thinks* a full document has been found in the input stream. Because the normal parser is implemented as an extension (instead of userland PHP), this turns out to be pretty fast for streams that contain common, rather small objects.

You might want to use this if

- you have to deal with a stream of multiple JSON documents
- you have to handle chunks of incomplete JSON documents
- you prefer a lightweight parser

You probably don't want to use this if

- you deal with complete JSON documents
- you have a proper delimiter (such as newlines) between your individual JSON documents
- your JSON documents are too big to fit into RAM
- you have a CS background and/or are in love with actual incremental, recursive parsers

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org/). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This project does not currently follow [SemVer](https://semver.org/). This will install the latest supported version:

```
$ composer require clue/json-stream:^0.1.1
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's *highly recommended to use PHP 7+* for this project.

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](https://getcomposer.org/):

```
$ composer install
```

To run the test suite, go to the project root and run:

```
$ php vendor/bin/phpunit
```

License
-------

[](#license)

This project is released under the permissive [MIT license](LICENSE).

> Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

More
----

[](#more)

- If you want to efficiently process (possibly infinite) streams of data, you may want to use [clue/reactphp-ndjson](https://github.com/clue/reactphp-ndjson)to process newline-delimited JSON (NDJSON) files (`.ndjson` file extension).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65% 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 ~2110 days

Total

2

Last Release

2021d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/776829?v=4)[Christian Lück](/maintainers/clue)[@clue](https://github.com/clue)

---

Top Contributors

[![clue](https://avatars.githubusercontent.com/u/776829?v=4)](https://github.com/clue "clue (13 commits)")[![SimonFrings](https://avatars.githubusercontent.com/u/44357440?v=4)](https://github.com/SimonFrings "SimonFrings (6 commits)")[![PaulRotmann](https://avatars.githubusercontent.com/u/85174210?v=4)](https://github.com/PaulRotmann "PaulRotmann (1 commits)")

---

Tags

jsonstreaming parserincremental parser

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clue-json-stream/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

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

Declaratively specify how to extract elements from a JSON document

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

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

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

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

1.8k92.4M680](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30525.1M57](/packages/colinodell-json5)[clue/ndjson-react

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

15882.2M31](/packages/clue-ndjson-react)

PHPackages © 2026

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