networkteam / json-seq
JSON Text Sequences (RFC7464) encoder and decoder
Installs: 22 132
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.1 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is auto-updated.
Last update: 2024-12-11 10:33:03 UTC
README
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.