Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ event driven json stream reader

I just discovered YAJL project which just does what I need.

  • Read from stream
  • Callback on each valid parsed token
  • Reparse incomplete json when new data arrived

But I prefer C++. Of course I can use this library from C++ project and even write my own wrapper if I really want to but anyway native C++ is preferable.

I looked at JsonCPP but looks like it can't read incomplete json data from stream.

Is there any other C++ libraries for parsing json streams?

Some more requirements:

  • lightweight. boost or Qt are not suitable
  • I need something what I may freely use in commercial closed source software (mit, public domain, etc).
  • Support for not blocking read. or allow to feed data (append_incoming_data).
like image 511
Sergey Avatar asked Dec 27 '12 11:12

Sergey


1 Answers

Recently I search library with similar requirements, and actually found only 1.5 libraries that support such requirements:

  1. https://github.com/kazuho/picojson

one header library, BSD licence, and have interface like this:

Iter parse(value& out, const Iter& first, const Iter& last, std::string* err);

so you can create append_incoming_data with a couple of lines of code.

  1. https://github.com/dropbox/json11 one file library, licence similar to BSD, c++11 support, but interface that allow parse partly arrived from network json it require patch:

https://github.com/dropbox/json11/pull/55

P.S.

lightweight. boost or Qt are not suitable

Actually, they are not suitable because of

allow to feed data

At now both Qt5 json and boost property_tree can not parse half ready json.

like image 190
fghj Avatar answered Oct 17 '22 18:10

fghj