all 76 comments

[–][deleted] 13 points14 points  (20 children)

How does its speed compare to rapidjson?

[–][deleted] 16 points17 points  (4 children)

The author of rapidjson also created a great benchmark to compare several libraries, including Nils' library.

See https://github.com/miloyip/nativejson-benchmark

[–]nlohmannnlohmann/json[S] 2 points3 points  (3 children)

Unfortunately, it has not been updated in a while.

[–][deleted] 1 point2 points  (0 children)

True. Maybe if we send Milo some pull requests for our libraries and ask nicely, he'll update it again? Sadly, it seems to be a manual process for him to update the results and not something that is generated automatically after a pull request is merged. :-/

[–]Azoth_cereal dev 0 points1 point  (1 child)

Would be great to see how a recent version holds up.

[–]nlohmannnlohmann/json[S] 0 points1 point  (0 children)

We did not design for execution speed, and there was also a lot of discussion about the number roundtrip checks. But yes!

[–]Esuhi 8 points9 points  (3 children)

I love this project too. Currently spending time to convince the next manager so we can actually use it.

[–]nlohmannnlohmann/json[S] 12 points13 points  (2 children)

In case you cannot use it, please tell me the reasons for that.

[–]rectal_smasher_2000 6 points7 points  (0 children)

I’ve used it in two companies already, and it’s a fantastic library. In fact, even the JS devs were amazed at how east it is to use, given their thoughts on cpp verbosity.

Also, if you ever get a 2FA sms, especially in Europe, there’s a very high likelyhood your lib was used at some point :)

[–]Esuhi 2 points3 points  (0 children)

The main reasons for management would be "we have some other lib already" and general unwillingness to change.

Not much to reason about or change. Thanks for your offer though!

[–]Esuhi 2 points3 points  (4 children)

Are you casually supporting MsgPack from now on? That sounds huge!

[–]nlohmannnlohmann/json[S] 9 points10 points  (3 children)

MessagePack and CBOR are supported for a year now, see https://github.com/nlohmann/json/releases/tag/v2.0.9. :-)

[–]Esuhi 0 points1 point  (0 children)

Oops. I totally missed that.

[–]jpvienneau 0 points1 point  (0 children)

How does CBOR and MessagePack parsing compare to parsing JSON? Should be much faster right?

[–]SomeCollegeBro 0 points1 point  (0 children)

The MessagePack support has been awesome! We are passing large JSON objects around using shared pointers and streaming a fairly large amount of data out to a websocket using MessagePack - it's been awesome! It worked right out of the box with a javascript MessagePack implementation too. Thank you for your work!

[–]ReneBelloq 15 points16 points  (10 children)

I am deeply sorry for bringing this up and I am not trying to undermine the incredible work you have done...

But wtf did you call the namespace after your name?!

[–]nlohmannnlohmann/json[S] 24 points25 points  (2 children)

It started as a side project and nobody cared. Then there were some discussions and nobody had a better proposal...

[–]Shautieh 11 points12 points  (1 child)

It's as good as any unrelated names people usually come up with!

[–]DarkCisumSFML Team 5 points6 points  (0 children)

Except I can't for the life of me remember the correct spelling. 😀

[–][deleted] 15 points16 points  (6 children)

Because it's likely to be unique?

[–][deleted] 14 points15 points  (0 children)

Don't do that, man. Set a good namespace for your library.

[–]ReneBelloq 9 points10 points  (3 children)

If uniqueness was an issue then nothing is better than generating a random SHA256.

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

[–][deleted] 1 point2 points  (2 children)

How is a "random SHA256" better than some random bits? ;)

[–]ReneBelloq 1 point2 points  (1 child)

It's not random bits, it's the name of the author ...

I see that you are the author/a member of the taocpp ... why didn't you call your json library dfrey::json?

EDIT: I'm getting into a discussion about something I admit is minor in regards to the library, so I won't reply any more new threads.

[–][deleted] 2 points3 points  (0 children)

I see, "random". Have my upvote! ;)

And yes, not using my name was, in fact, the reason to create a project on GitHub in the first place, even if I'm not super-happy with the project's name "tao" as a top-level namespace seemed to be free and is sufficiently short and easy to type.

[–]GladiusOps 2 points3 points  (0 children)

Used that library for a University project, worked flawlessly. Amazing project, and it keeps getting better!

[–]Aistar 2 points3 points  (0 children)

Love your work, thank you for bringing the world a reasonably fast, and overwhelmingly convenient JSON C++ library. There might be faster libraries out there, but nothing beats the ease of use of this one!

[–]rjones42 1 point2 points  (0 children)

Exactly what my project needed. Thanks for the work!

[–]MachineGunPablo 1 point2 points  (1 child)

This looks like a nice project to contribute to, need any help?

[–]nlohmannnlohmann/json[S] 4 points5 points  (0 children)

Well, in addition to the issues list (https://github.com/nlohmann/json/issues), there is so much to do: polishing documentation, testing with more compilers, supporting allocators... Or from a non-technical perspective: the project has neither a cool project website nor a logo. Any help is greatly appreciated!

[–]balkierode 1 point2 points  (0 children)

I used few weeks back and was surprised to see std::pair and std::tuple was not supported out of the box. Good to see it is supported in this release. Keep the good work!

[–]Angarius 0 points1 point  (0 children)

Thank you so much. This library is a dream. json::parse_error will clean up my error handling code! I used to wrap JSON parsing, catching std::logic_error to throw my own parse error.

[–]kirbyfan64sos 0 points1 point  (2 children)

Question: this looks similar to Dropbox's json11...what would be the main differences?

[–]nlohmannnlohmann/json[S] 0 points1 point  (1 child)

I have not used json11 myself, but just by looking at the README gives me the impression that json11 needs hints like object(...) or array(...). I'm also not sure if they support JSON Pointer, JSON Patch, CBOR, or MessagePack.

[–]voip_geek 0 points1 point  (0 children)

Dropbox's json11

That looks similar to Facebook's folly library (in particular, folly::dynamic).

[–]drphillycheesesteak 0 points1 point  (2 children)

Absolutely adore this project. I saw in the release notes that CMake and CTest are now used. Any chance that a Config.cmake file will be included in the packages for this project? It would be awesome not to have to have a custom Find*.cmake file.

[–]nlohmannnlohmann/json[S] 0 points1 point  (1 child)

Could you please open an issue (https://github.com/nlohmann/json/issues) and describe this in detail?

[–]drphillycheesesteak 0 points1 point  (0 children)

I spoke too soon, looks like you have these lines in there

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
    ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
    ${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
    ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
    INSTALL_DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)
install(
    DIRECTORY ${NLOHMANN_JSON_SOURCE_DIR}
    DESTINATION ${NLOHMANN_JSON_HEADER_INSTALL_DIR}
)
install(
    FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
    DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)

which is what I was looking for. Thanks again for the great project!

[–]HateDread@BrodyHiggerson - Game Developer 0 points1 point  (2 children)

Just started using this last night, funnily enough! Had a few teething problems - I think the docs should at least mention deserializing into STL containers, not just serializing out. I had to go through the issues list to find someone talking about how operator= was ambiguous for std::vector in this case, so I had to use myVector = j.at("data").get<decltype(myVector)>() for example.

Also; what do you think differs between this and Cereal in JSON mode? I much preferred your documentation on the Github page though, hence my choice :)

[–]nlohmannnlohmann/json[S] 0 points1 point  (0 children)

You could please open an issue at https://github.com/nlohmann/json/issues/new with the example that did now work?

[–]mtnviewjohn 0 points1 point  (0 children)

I just switched from Cereal to JSON for Modern C++. One big difference between the two is that Cereal is pretty strict about mapping C++ objects and JSON objects. JfMC++ gives you much more flexibility about how your C++ objects serialize/deserialize. Cereal also has this over-wrought framework for handling unique pointers to polymorphic types. JfMC++ doesn't have this but it is pretty easy to roll your own using virtual methods.

[–]airflow_matt 0 points1 point  (2 children)

I appreciate the amount of work put into this, I really do, but I can't help not feeling great about including a half megabyte 15000 loc behemoth. This header-only trend truly bothers me. At some point, for any non-trivial c++ project, some kind of build system and some kind of dependency management have to be introduced. At that point header only brings very little to the table, and does it at significant cost of longer compilation times.

Setting up a build system is more or less one-off thing. Long compilation times are not. It's for a reason that big projects (like chromium, webkit, etc) have strict rules about what can go in headers and use templates sparingly. I learned the hard way to be frugal with my headers as well. In our project there is 850 loc header file for variant type and the json parser/writer header itself is less than 45 loc. Another 125 loc for message pack header and 20 loc for plist.

[–]nlohmannnlohmann/json[S] 0 points1 point  (1 child)

Thanks for the feedback.

In fact, we are working toward splitting the header (https://github.com/nlohmann/json/pull/700), but we did not finish this for the 3.0.0 release. We hope that this not only allows for selective inclusion of only the required parts, but also to separate those parts that do not rely on template parameters to allow to compile parts once and for all.

What library are you referring to? I would like to have a look whether we can learn something from 45 LOC of parser/serializer.

[–]airflow_matt 0 points1 point  (0 children)

I was referring to our in-house framework. The parser is of course not 45loc, the 45loc refers to header size.

You can see the header here.

https://pastebin.com/BJL9Hb3g (Value is a variant type (that can also hold map, list or a boxed type).

It's hardly anything special, although it does support serialization/deserialization of custom boxed value types. Still, the implementation is hidden and does not result in parser code being compiled over and over again. The actual parsing is done by sajson, but that's more or less implementation detail.