8

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).
Sergey
  • 323
  • 4
  • 10
  • I am sure http://json.org had at least a few C++ implementations. Scroll down on the main page. – Bartek Banachewicz Dec 27 '12 at 11:41
  • non of them are suitable. I'll correct my question with more requirements – Sergey Dec 27 '12 at 13:00
  • There are 11 different implementations for C++ alone (excluding C). _Surely_ there's one there that will do what you need? – Bojangles Dec 27 '12 at 13:10
  • they all have some flaws: blocking and don't have feed method, expecting complete json, stupid implementation allowing to parse only subset of json. It's from first look. maybe I'm wrong for some – Sergey Dec 27 '12 at 14:06
  • @Rion did you find what you want? – fghj Apr 26 '16 at 12:32
  • @user1034749, as far as I remember, no. – Sergey Apr 30 '16 at 05:18
  • new arrivals to this thread may want to check [boost json stream reader](https://www.boost.org/doc/libs/1_77_0/libs/json/doc/html/json/ref/boost__json__stream_parser.html). – Paul Rooney Sep 21 '21 at 12:12

2 Answers2

3

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.

fghj
  • 8,898
  • 4
  • 28
  • 56
0

Other options are

  • sjparser - the parsing is based on schema specified
  • JsonReader - plain event based parser
Flaviu
  • 931
  • 11
  • 16