Open acuozzo opened 5 years ago
Yup, this is true, and your expectations for json_peek() are reasonable.
This may not be the expected behavior but perhaps it's the simplest? The two alternative semantics that come to mind are:
json_get_*()
return values corresponding to the last json_next()
event and there is no way to get values for the peeked event.
As the first option but there is an additional API to get the values corresponding to the peeked event (e.g., a parallel json_peek_*()
family of functions).
The first option will be simpler to implement but it will be a limitation compared to the current semantics (which allows one to retrieve both values). I believe the second option will lead to quite a bit of additional complexity (second set of values, their management, etc).
So perhaps the current semantics is not that bad? Either way, it would be helpful to clarify what the future approach will be (I am currently working on a JSON parser for C++ that is based on pdjson and it would be helpful to know if I can rely on the current semantics).
json_peek() seems as though it should be non-destructive, but since it calls json_next() it changes the value returned by json_get_position().
It similarly changes the value returned by json_get_string() and friends.