json-machine icon indicating copy to clipboard operation
json-machine copied to clipboard

Wildcard pointer doesn't work properly

Open antonMilukov opened this issue 3 years ago • 1 comments

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']);

  • my code example below:
<?php 

$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)

antonMilukov avatar Mar 22 '22 15:03 antonMilukov

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 avatar Mar 24 '22 17:03 halaxa

Hi @antonMilukov, does #83 solve your problem?

halaxa avatar Oct 08 '22 12:10 halaxa

Can this be closed, @antonMilukov ?

halaxa avatar Dec 17 '22 22:12 halaxa

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

halaxa avatar May 13 '23 09:05 halaxa