Json: Incremental parsing: Where's the push version?

Created on 3 Jun 2017  路  11Comments  路  Source: nlohmann/json

The promotional materials cite "incremental parsing" but where is the interface that lets me call into the parser with a buffer at a time?

I see the "pull" interface where it reads from a stream - where's the push?

question

Most helpful comment

Alright - I never "promised" push parsing. ;)

All 11 comments

Do you mean the line

Aaron Burghardt implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing.

?

I think so. What I'd like is to declare an object that holds the parser state, and then call it one or more times with buffers holding pieces of the incoming JSON stream until the serialized JSON is complete. Then take ownership of the tree from the parser.

The mentioned paragraph refers to the parser from std::istream. There, it is possible to call the parser multiple times on a stream and read a JSON value each. See #367 for details.

Your described usecase is interesting, but currently not possible.

Fair enough. Note that reading from std::istream is "pull" parsing: the parser requests buffers until the parse is complete before returning.

Alright - I never "promised" push parsing. ;)

Context: I am looking for a JSON pull parser to use as an example in my HTTP library Beast (being proposed for Boost). I want to show how you can declare a custom "Body" type which parses incoming JSON from HTTP requests on the fly. Hence the need for a push parser that operates incrementally on buffers.

Believe it or not, NONE of the JSON libraries that I have found with my Google searching have pull parsing as a feature! If yours was the first, I could feature your library in my examples :)

Beast:
https://github.com/vinniefalco/Beast/

I understand. The "issue" is, that I aim for an intuitive API and currently I tried not to expose the parser class to the user, so I am not sure whether such a parser would really benefit this library.

I think this is nothing I can realize right now.

623 discusses a restructuring of the parser class. Maybe this issue can be reviewed there as well.

Related: #971

Someone can always work around it by 'pushing' it to a suspending iterator in another thread, or in a coroutine via Boost.Fiber or Boost.Coroutine2 or whatever as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

past-due picture past-due  路  4Comments

qis picture qis  路  4Comments

Prati369 picture Prati369  路  4Comments

jmlemetayer picture jmlemetayer  路  3Comments

Fonger picture Fonger  路  4Comments