kelunik / streaming-json
A streaming JSON parser for Amp.
v1.0.0
2017-07-10 10:01 UTC
Requires
- amphp/amp: ^2
- amphp/byte-stream: ^1
- amphp/socket: ^0.10
- daverandom/exceptional-json: ^1.0.1
Requires (Dev)
- amphp/artax: ^3
- amphp/phpunit-util: ^1
- friendsofphp/php-cs-fixer: ^2.3
This package is auto-updated.
Last update: 2024-11-15 07:43:12 UTC
README
A streaming JSON parser for Amp.
Installation
composer require kelunik/streaming-json
Usage
$parser = new StreamingJsonParser($inputStream); while (yield $parser->advance()) { $parsedItem = $parser->getCurrent(); }
Options can be passed to the constructor just like for json_decode
. The parser will consume the passed input stream and is itself an Amp\Iterator
that allows consumption of all parsed items. Any malformed message will fail the parser. If the input stream ends, the parser will try to parse the last item and will complete the iterator successfully or fail it, depending on whether the last item was malformed or not.