rapidjson
rapidjson copied to clipboard
Feature Request: Pull-Style Reader
For streaming access to JSON, a pull-style reader/parser has a number of advantages over a push-style (SAX-like) API, including ease of use and performance.
Here's https://learn.microsoft.com/en-us/archive/msdn-magazine/2003/may/manipulating-xml-data-with-integrated-readers-and-writers-in-net discussing this topic in the context of XML and .NET:
The XmlReader pull model has several advantages over the more common SAX-like push model (see Figure 3). First and foremost, the pull model is easier to use. It's just easier for developers to think about while loops than complicated state machines. Although contextual state management is still a challenge with the pull model, it's easier to deal with through consumer-driven procedural techniques that are more natural to most developers.
The pull model can also offer improved performance through a variety of techniques. XmlReaders can take advantage of client hints to make more efficient use of character buffers (such as avoiding needless string copies). It's also possible for consumers to perform selective processing (skip over elements of no interest, don't expand entities, and so on). With a push model, everything has to be passed through the application because the reader has no way of knowing what's important.
In the end, the pull model offers a more familiar programming model along with several performance benefits. If you're still a push model aficionado, you can always layer a set of push-style interfaces on top of the XmlReader pull model, but the reverse is not true. A sample SAX2 implementation layered over XmlReader may ship with the .NET Framework SDK.
Could rapidjson provide a pull-style parser, and have its existing SAX-style support layerd on top of this pull model?