Skip to content

kelunik/streaming-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

streaming-json

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.