PHPackages                             sop/json-generator-parser - 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. sop/json-generator-parser

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

sop/json-generator-parser
=========================

Event-driven recursion free SAX-style parser for JSON fed by generator

v0.1.1(5mo ago)06MITPHPPHP &gt;=8.2

Since Dec 11Pushed 5mo agoCompare

[ Source](https://github.com/sop/json-generator-parser)[ Packagist](https://packagist.org/packages/sop/json-generator-parser)[ Docs](https://github.com/sop/json-generator-parser)[ RSS](/packages/sop-json-generator-parser/feed)WikiDiscussions master Synced 1mo ago

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

JSON Generator Parser
=====================

[](#json-generator-parser)

[![CircleCI](https://camo.githubusercontent.com/6146dc756d339e04740ac3f15cae23c00073c2c2e71d246acdfb798aa2593978/68747470733a2f2f646c2e636972636c6563692e636f6d2f7374617475732d62616467652f696d672f67682f736f702f6a736f6e2d67656e657261746f722d7061727365722f747265652f6d61737465722e7376673f7374796c653d737667)](https://dl.circleci.com/status-badge/redirect/gh/sop/json-generator-parser/tree/master)[![Coverage Status](https://camo.githubusercontent.com/78d8109edf2a5debbfe569bfe34e7de7478c4635aef43c2b3af3cee2fa5a827c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736f702f6a736f6e2d67656e657261746f722d7061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sop/json-generator-parser?branch=master)[![License](https://camo.githubusercontent.com/365ad2a045e305c6072fb4b440c96210cdce0b30ab2ec610729018011888d75d/68747470733a2f2f706f7365722e707567782e6f72672f736f702f6a736f6e2d67656e657261746f722d7061727365722f6c6963656e7365)](https://github.com/sop/json-generator-parser/blob/master/LICENSE)

A PHP library for event-driven recursion free SAX-style JSON parser fed by generator.

Rationale
---------

[](#rationale)

Provide a JSON parser with lenient rules that accepts input from an LLM stream.

There are cases where you need a structured LLM response, but want to display output to the user as soon as there are token stream available. This library provides a listener interface, that is called as JSON is parsed.

As LLM's may generate a bit wonky JSON, this library has a non-strict option that permits various JSON errors, which wouldn't change the semantic meaning of the response.

Requirements
------------

[](#requirements)

- PHP &gt;=8.2

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

[](#installation)

This library is available on [Packagist](https://packagist.org/packages/sop/json-generator-parser).

```
composer require sop/json-generator-parser
```

Example
-------

[](#example)

Here we receive a stream from LLM HTTP API. We assume that stream is already processed such that `$lines` generator yields logical SSE lines.

```
$lines = ... // Generator that produces lines from HTTP SSE stream
$input = (function (Generator $lines): Generator {
    foreach ($lines as $line) {
        // Just an example, no error checking nor validation
        if (!str_starts_with($line, 'data:')) {
            continue;
        }
        $json = trim(substr($line, 5));
        $data = json_decode($json);
        // Yield content delta chunks
        if (!empty($data->choices[0]->delta->content)) {
            yield $data->choices[0]->delta->content;
        }
    }
})($lines);
$listener = new CallbackJSONListener(
    function (array $keys, mixed $value): void {
        // Here you can handle parsed values.
        // Keys contain all structural indices leading to the value.
        // eg. for `{"a":["x","y","z"]}` JSON the second array value would
        // have keys ["a", 1] and value "y"
    }
);
$parser = new JSONGeneratorParser($listener, false);
$parser->parse($input, true);
```

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance72

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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

Total

2

Last Release

158d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35cf70dd6be68d37fd42490e3ad9c199d2a1f1dd4420f71658998b7d8b694e97?d=identicon)[sop](/maintainers/sop)

---

Top Contributors

[![sop](https://avatars.githubusercontent.com/u/1017000?v=4)](https://github.com/sop "sop (24 commits)")

---

Tags

jsonparserphpjsongenerator

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sop-json-generator-parser/health.svg)

```
[![Health](https://phpackages.com/badges/sop-json-generator-parser/health.svg)](https://phpackages.com/packages/sop-json-generator-parser)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

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

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

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

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

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

15467.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

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