tags:

views:

16296

answers:

6

I've seen the C++ JSON links on www.json.org but would like some feedback on which parser people prefer - for reliability, speed and ease of use.

Thanks, Sam

+24  A: 

I looked at most of them a year or so ago, and settled on JsonCpp (http://jsoncpp.sourceforge.net/). I've found it reliable, fast and easy to use, so 3/3.

mpd
I'm using jsoncpp also. it requires a little clean-up on my (work) system so integrations for new revisions are a little harder
George
Doesn't appear to work on Linux (amd64) -- the library compiles, but fails to parse anything.
Jyaan
+23  A: 

I'm using JSON Spirit on a project at the moment, I'm impressed with it so far.

Note that it does rely on Boost (if only for headers).

Handy features:

  • Has Unicode support.
  • Uses std::vector to hold Arrays which helps interoperability.
  • Provides a pretty print function (write_formatted).
  • Has read and write functions for strings and streams.

Note that Objects are also implemented using vector (not map), which means slower access, but it does mean that the order of elements is maintained.

therefromhere
Boost is (mostly) only headers: http://www.boost.org/doc/libs/1_36_0/more/getting_started/windows.html#header-only-libraries
mpd
Yeah, but the reason I mention it is that you need to link against Boost Threads if you want to use JSON Spirit in multiple threads.
therefromhere
Just a small note, but it looks like newer versions (after 4.0) are able to store objects in both vectors or maps (configurable as a template parameter).
Magnus Österlind
+6  A: 

See also Boost property_tree included in the 1.41.0 release of Boost:

http://www.boost.org/doc/libs/1_41_0/doc/html/property_tree.html

Basically it provides a generic property tree structure and includes parses/generators for JSON, XML and INI. It is header only and it uses Boost Spirit for generation/parsing.

Marty McFly
Boost property_tree does not fully support all type information. From the documentation: JSON values are mapped to nodes containing the value. However, all type information is lost; numbers, as well as the literals "null", "true" and "false" are simply mapped to their string form.
Yukiko
+1  A: 

jsoncpp is the way to go

A: 

I just gave JSON Spirit (the header-only version) a try, because I was already using Boost in my project and JSON Spirit only depends on Boost.

However, I think the documentation (especially for the new header-only version) is not adequate at the moment. Maybe this will change.

BarackBush
+1  A: 

I know you are asking about the C++, but yajl is definitely worth to try as well. It has many features that is not available from many other parsers, and the most important, it's fast.

Spike
Could you elaborate on features it has over alternatives. I am looking for a C only JSON parser, saw yacl and am interested in knowing how it differs from competition.
StaxMan