halaxa / json-machine

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

Multiple JSON Pointers #61

Closed fwolfsjaeger closed 2 years ago

fwolfsjaeger commented 3 years ago

I also need the "unused" (not iterated) JSON, so I've extended your code to store this in a variable. I hope you don't mind.

fwolfsjaeger commented 2 years ago

Because I thought it was faulty, which it actually was not. Also, my commit to fix JsonMachine\Parser::getCurrentJsonPointer() was faulty, it is correct now.

halaxa commented 2 years ago

Awesome, thank you. I'll try to do the final review asap.

fwolfsjaeger commented 2 years ago

JsonMachine\Items::normalizeOptions() checks if the given 'pointer' key has a string value. I'll amend the check to not throw an exception if there is a 'pointers' key with an array value.

halaxa commented 2 years ago

Ok, thanks.

halaxa commented 2 years ago

I have a question. I am probably missing something. What is Parser::$jsonPointer used for at this moment? Doesn't its purpose overlap with Parser::$currentJsonPath?

fwolfsjaeger commented 2 years ago

Parser::$jsonPointer is the matched JSON pointer, it can be fetched using Parser::getMatchedJsonPointer(): eg. /items/- Parser::$currentJsonPath is the current JSON path, it's needed for Parser::getCurrentJsonPointer(): eg. /items/0

halaxa commented 2 years ago

OK, so then

Can you do it or should I?

fwolfsjaeger commented 2 years ago

Parser::getJsonPointer() still returns the passed JSON pointer when inside the iteration. But fine, I have changed it so that it always just returns the first JSON pointer, it won't work with multiple pointers anymore. Parser::$jsonPointer is named Parser::$matchedJsonPointer now.

halaxa commented 2 years ago

it won't work with multiple pointers anymore.

That's ok as it should keep previous functionality. I plan to make 0.9.0 before 1.0.0 so I'd like to keep BC.

Parser::$jsonPointer is named Parser::$matchedJsonPointer now.

Thanks :)