News for hackers. Stuff that matters.
Re:JSON for Modern C++ by einpoklum on Sunday September 29, 2019 @05:25AM (#21106046)
How does this compare with RapidJSON, JSONCpp and JSON Spirit - other popular C++ JSON parser libraries?

Links:

http://rapidjson.org/ https://github.com/Tencent/rapidjson

https://github.com/open-source-parsers/jsoncpp

https://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-J...

Re:JSON for Modern C++ by Kh4L on Sunday September 29, 2019 @05:34AM (#21106073)
We used to use. We first micro-benchmarked all those and we found that Tencent/rapidjson was more than 100% faster than nlohmann/json :)

Our primary use is to parse http://cocodataset.org/ metadata files and RapidJson is 100% faster.

Re:JSON for Modern C++ by doublerebel on Sunday September 29, 2019 @10:58AM (#21107379)
RapidJson is very efficient. I have used several JSON libraries for C++, and right now I'm really enjoying json_dto, which is built on RapidJson. It has great developer UX, including the most succint syntax I've used, and support for std::optional.

https://github.com/Stiffstream/json_dto

Re:JSON for Modern C++ by e12e on Sunday September 29, 2019 @06:55AM (#21106321)
> 100% faster.

So, twice as fast - it parses the dataset in half the time?

Re:JSON for Modern C++ by Kh4L on Sunday September 29, 2019 @05:45AM (#21106117)
On the other hand, nlohmann/json has a cleaner and more Python-like API, so if you don't care about performance that much, I'd say it's the way to go
Re:JSON for Modern C++ by vips7L on Sunday September 29, 2019 @06:50AM (#21106304)
Does anyone write C++ and not care about performance?
Re:JSON for Modern C++ by polymonster on Sunday September 29, 2019 @07:35AM (#21106448)
We use C++ and care about real time performance, but also use this JSON library, the thing is that we use JSON for loading and configuring data which happens during load time which is infrequent and don’t need JSON during the critical update path.

Previously we used rapid json which is faster but the syntax of the nlohmann json is nicer and it is much quicker to develop with.. we also use python a lot so the familiarity between the 2 is also useful, some of the other C++ json libs can have quite convoluted api’s for dealing with values, objects and arrays.

Re:JSON for Modern C++ by dguest on Sunday September 29, 2019 @07:37AM (#21106457)
On the other hand: I'm a bit surprised at how many people are writing JSON and care about the performance.

The overwhelming majority of our IO is reading / writing data files, but those are stored in an optimized binary format. The configuration / metadata accounts for a much smaller fraction of IO. For this tiny fraction we care about flexibility and readability, a slow JSON parser is fine.

Re:JSON for Modern C++ by human20190310 on Sunday September 29, 2019 @11:37AM (#21107631)
While I agree that in many cases JSON parsing is not the largest consumer of resources, it really sucks when it is.

At some point it seems like a general mindset shifted from making things efficient at every level to assuming things don’t matter if you’re probably doing something worse anyway.

Re:JSON for Modern C++ by Cynox on Sunday September 29, 2019 @07:01AM (#21106348)
If you use C++ for CPU-intensive tasks, then yes, in this case. E.g. reading 1kb of input, churning numbers for 10 minutes and outputting an h5 file. If you use C++ for IO-intensive tasks, then your tradeoff is probably different and you would optimise your IO for speed and not readability.
Re:JSON for Modern C++ by einpoklum on Sunday September 29, 2019 @07:45AM (#21106482)
If you know you only get small JSON files, e.g. for configuration and so on, then - yes, you might not care about the parser performance and be more interested in the elegance of its API.
Re:JSON for Modern C++ by johannes1234321 on Sunday September 29, 2019 @08:12AM (#21106586)
This is not a Boolean thing. If I spend a "long" time in processing the data in my business logic the time spent to load the data or storing the result can be neglectable.

If reading/writing is the hot path things are different, though.

Re:JSON for Modern C++ by pingyong on Monday September 30, 2019 @08:40AM (#21114682)
First of all absolutely, but more importantly who cares about the performance of your json parsing? I can only think of very few applications where that would be relevant at all, even if you care about performance in general.
Re:JSON for Modern C++ by shultays on Sunday September 29, 2019 @05:46PM (#21109809)
You dont necerrarily need to care for everything to be performant.
Re:JSON for Modern C++ by gdy on Sunday September 29, 2019 @10:22AM (#21107184)
If that's a configuration file which is read once - yes
Re:JSON for Modern C++ by SloopJon on Sunday September 29, 2019 @03:06PM (#21109004)
This is a very convenient library for getting started. It even has a mode that made it possible for me to parse numbers into a decimal class.

I would point out that its convenience in large part depends on extensive use of cast operators, which can lead to some tricky corner cases. It is also the only component in one of my projects that confuses xlclang++ on AIX.

Re:JSON for Modern C++ by gumby on Sunday September 29, 2019 @02:12PM (#21108633)
I switched from rapidjson to this library (nlohmann's) because it is so simple to use and integrates into C++ very cleanly.

If I had enormous globs of JSON to read I might use something faster (I believe there's a very fast library that uses SIMD instructions) but my needs are quite limited: basically exchanging snippets of JSON with a network service. So clarity was far more important than performance.