networkteam/json-seq

JSON Text Sequences (RFC7464) encoder and decoder

v1.1.0 2023-09-11 07:54 UTC

This package is auto-updated.

Last update: 2024-11-11 10:20:35 UTC


README

Latest Version Build Status Code Coverage Quality Score Total Downloads

JSON Text Sequences (RFC7464) encoder and decoder for PHP

JSON Text Sequences define a streamable JSON encoding and parsing based on a delimiter for multiple JSON encoded texts.

See https://tools.ietf.org/html/rfc7464 for the JSON Text Sequences RFC.

Install

Via Composer

$ composer require networkteam/json-seq

Usage

Encoding data in JSON Text Sequences:

$stringWriter = new StringWriter();
$encoder = new Encoder($stringWriter);

$encoder->emit(['id' => '1', ...]);
$encoder->emit(['id' => '2', ...]);

$result = $stringWriter->getString();

Decoding JSON Text Sequences from a string:

$jsonTexts = "\x1E{...}\x0A\x1E{...}\x0A";

$decoder = new StringDecoder();
foreach ($decoder->decode($jsonTexts) as $data) {
    // process $data
}

Testing

$ composer test

License

The MIT License (MIT). Please see License File for more information.