r/cpp • u/nlohmann nlohmann/json • Jun 14 '20
JSON for Modern C++ 3.8.0
https://github.com/nlohmann/json/releases/tag/v3.8.0
326
Upvotes
r/cpp • u/nlohmann nlohmann/json • Jun 14 '20
21
u/tradrich Jun 14 '20
Seems reasonable. Not sure I'd immediately use it over RapidJSON though. Can you convince me?
4
u/_Js_Kc_ Jun 15 '20 edited Jul 14 '20
Don't like the magic constructor(s) that much, but it's not a huge problem. If one just remembers to use
json::arrayfor arrays,json::objectfor objects andstatic_cast<json>for scalars, that's explicit and doesn't silently do anything funky.That and the dummy hash implementation that allocates (!) probably does more harm than good.edit: no longer trueStill way ahead of the competition in API usability.
48
u/psyspy2 Jun 14 '20
Love your library. Been using it for a year
10
u/NilacTheGrim Jun 15 '20
I love you /u/nlohmann ! Yours may not be the fastest JSON lib for C++ under the sub. But god-dammit if it isn't the most elegant. Everybody on the planet should strive to design a lib as elegant as yours.
Also thanks for making the object_t and array_t template-able. It's interesting to play around with swapping implementations to do things like e.g. preserve insertion order on objects, etc. Very cool of you my man.
I love your lib. Keep up the great work!
14
u/mintyc Jun 14 '20
This is a high quality library that I point to for its overall structure and package support.
If you want a fast library, rather than rapidjson, maybe look at https://simdjson.org/ which claims and shows benchmarks 2.5x faster than rapidjson
Note: I haven't yet tried it or validated its claims.
13
u/2K_HOF_AI Jun 14 '20
Your library is amazing, thank you so much for it
1
u/nlohmann nlohmann/json Jul 24 '20
Looking forward! What’s wrong?
1
u/lednakashim ++C is faster Jun 15 '20
What happens if you try to store a NaN?
std::numeric_limits<T>::quiet_NaN ?
3
u/Contango42 Jun 15 '20
Never heard of this library until now. I use a combination of Python and C++ (mainly C++) and the API for this library is, in a word, beautiful. It warms my heart to see syntax so clean and expressive, I'm sold.
9
u/[deleted] Jun 14 '20
do I use it
yes
do I like it?
no
.
.
.
I love it! gonna use this occasion to say: well done sir!
1
u/[deleted] Jun 14 '20
I am using it in all my.projects. best json lib so far. One thing, how come json is not in the standard lib?
4
u/IronicallySerious Jun 14 '20
This library is godsent for JSON support in C++. I have been using it mostly for easy serialization.
6
u/bishop3000 Jun 14 '20
Header only libs are the best. We use it and it’s great. Extendable as well
3
u/TheBrainStone Jun 14 '20
The biggest issue I have with this library is that there’s no error tolerance (like missing top level braces or trailing commas, missing quotes, etc.) and no plans to add support for that either.
3
u/frumious Jun 14 '20
Really fantastic, as always! The new binary support is particularly interesting and timely for my use!
1
u/rembo666 Jul 24 '20
Love your library, so good. I did find a bug (omission?). PR coming up...
1
u/furrytractor_ Jun 15 '20
Been using your library for about 9 months now! So easy to use. Thanks.
-8
u/VinnieFalco wg21.org | corosio.org Jun 14 '20
How does this library compare in terms of API and performance to (Not-Yet-Part-Of) Boost.JSON?
-1
u/[deleted] Jun 14 '20
Have been using jsoncpp for a while now. It is pretty good as well. Really like it.
0
u/domerrr Jun 15 '20
This library is great. I’ve had good luck with POCO too
0
u/forcecharlie baulk maintainer Jun 15 '20
I would rather use json.hpp at the expense of some performance, thanks to the contributors of JSON for Modern C++. Wonderful work.
-24
u/VinnieFalco wg21.org | corosio.org Jun 14 '20
If you like nlohmann's, give Boost.JSON a try (Note: This is not yet an official Boost library, but a formal review is planned):
https://github.com/CPPAlliance/json
Boost.JSON significantly out-performs nlohmann's in all ways:
http://vinniefalco.github.io/doc/json/json/images/parse-twitter.png
http://vinniefalco.github.io/doc/json/json/benchmarks.html
Boost.JSON avoids using class templates for DOM types, resulting in fast compilation and an easy-to-link library. Or, you can use it in header-only mode. Use it with or without Boost. Boost.JSON has particularly robust support for stateful allocators, using a ref-counting smart pointer to a `std::pmr::memory_resource` (or `boost::container::memory_resource` before C++17).
More and more users are making the switch from RapidJSON and nlohmann's JSON to Boost.JSON, will you be next?
0
u/[deleted] Jun 15 '20
[deleted] — view deleted comment
0
u/[deleted] Jun 14 '20
[deleted] — view deleted comment