Live data from Hacker News

JSON for Modern C++

github.com

21–30 of 125 posts

Re: JSON for Modern C++

#21
post #12

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...

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

Does anyone write C++ and not care about performance?

Re: JSON for Modern C++

#22
post #11
post #6

I have been using json11 for a few years now ( https://github.com/dropbox/json11 ). It looks like it has been abandoned though. This seems like a great alternative.

I wouldn't say abandoned, it states in the README: Maintenance note: This repo is stable but no longer actively maintained. No further development is planned, and no new feature PRs will be merged. Bug fixes may be merged on a volunteer basis. With JSON being an unchanging spec this makes sense.

People are biased towards github repos with recent commits in github as opposed to projects that are stabilized and frozen. This is a loss considering the man-hours spent on creating a stable library.

Re: JSON for Modern C++

#23
post #9

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...

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.

> 100% faster.

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

Re: JSON for Modern C++

#24
post #21
post #12

Earlier quoted context omitted.

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

Does anyone write C++ and not care about performance?

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++

#25
post #21
post #12

Earlier quoted context omitted.

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

Does anyone write C++ and not care about performance?

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++

#26
post #21
post #12

Earlier quoted context omitted.

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

Does anyone write C++ and not care about performance?

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++

#27
post #21
post #12

Earlier quoted context omitted.

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

Does anyone write C++ and not care about performance?

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++

#28

I don't understand the JSON obsession. JSON as any other file format should be a small detail in any application and require very little plumbing code. In every application, any dependency to JSON should be minimized, contained and preferably eliminated.

I tried to suppress the urge to release my frustration, but seeing that the only slightly critical comment in this thread is the downvoted one let me forget my good intentions. WTF. 10s of thousands of line of code, > 10K lines in include files (yay compile times!) for a task that should be only a side concern and should be straightforward to implement. JSON has how many? 2? data types, and writing super efficient parser primitives for it must be easily possible to do in 99% of applications call for a massively oversized library like this. (Update, upon closer inspection I'm not even sure that speed is the main concern of this library. It really looks like it tries hard to be "Modern C++" by implementing all sorts of compile time insanity, bells and whistles (which will never fit 100% with clients and will be impossible to adapt)).

Re: JSON for Modern C++

#29
post #21
post #12

Earlier quoted context omitted.

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

Does anyone write C++ and not care about performance?

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++

#30
Note that this library basically requires exceptions to be enabled, which may or may not be the case in your environment.

(It is actually possible to use without, but then exceptions become aborts, and you have to dance around that.)

Post reply on HN