halaxa / json-machine

Efficient, easy-to-use, and fast PHP JSON stream parser
Apache License 2.0
1.08k stars 65 forks source link

Wildcard pointer doesn't work properly #78

Closed antonMilukov closed 1 year ago

antonMilukov commented 2 years ago

Hello! I have a problem to using wildcard pointer /results/-/color like in example from root documentation: as result I receive only 1st iteration and second is not available through the foreach or iterator

$fruits = Items::fromFile('fruitsArray.json', ['pointer' => '/results/-/color']);

$json = '{"results":[{"name":"apple","color":"red"},{"name":"pear","color":"yellow"},{"name":"some","color":"green"}]}'; $fruits = Items::fromString($json, ['pointer' => "/results/-/color"]);

var_dump(iterator_count($fruits->getIterator())); // result 1

foreach ($fruits as $key => $value) { echo "{$value}\n"; // result only red }



* also trying to pass the test of package and it's good 
* package version is 1.1.1

P.S: Your library is awesome)
halaxa commented 2 years ago

Hi, thanks for pointing that out. Are you able to add a failing test case? If so, add it as a case in \JsonMachineTest\ParserTest::data_testSyntax. Thanks.

halaxa commented 2 years ago

Hi @antonMilukov, does #83 solve your problem?

halaxa commented 1 year ago

Can this be closed, @antonMilukov ?

halaxa commented 1 year ago

Closing for now. Feel free to comment if the problem persists.