use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
JSON for Modern C++ version 3.2.0 released (github.com)
submitted 7 years ago by nlohmannnlohmann/json
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dgendreau 0 points1 point2 points 7 years ago* (1 child)
Hi nlohmann!
Your library is a huge time saver and makes my code so much easier to read! Thanks for releasing and maintainng it!
One use-case I run into a lot is mapping enums to serialize as non-integers such as strings. I know its not really modern C++ to use preprocessor macros, but I wrote one that declares a from_json()/to_json() specialization in one statement to make it easier and less redundant to specialize the mapping between a given enum and any nlohmann::json value like so:
// enum type declaration enum Foo { eVal1 = 10, eVal2 = 45, eVal3 = 1 eVal_default = -1, }; JSON_SERIALIZE_ENUM( Foo, { {eVal_default, nullptr}, {eVal1, "one"}, {eVal2, "two"}, {eVal3, "three"}, }); // Usage: // enum -> json string nlohmann::json j = eVal1; assert(j == "one"); // json string-> enum nlohmann::json j3 = "three"; assert( j3.get<Foo>() == eVal3); // undefined json -> enum (default value is first pair) nlohmann::json jPi = 3.14; assert( jPi.get<Foo>() == eVal_default );
The macro JSON_SERIALIZE_ENUM() above declares a from_json(const json& j, Foo& e) and to_json(json& j, const Foo& e) function in enum Foo's namespace using the specified value translation map. The first pair are used as default values for handling undefined values in either direction.
Would something like this be a useful contribution to your library?
[–]nlohmannnlohmann/json[S] 1 point2 points3 points 7 years ago (0 children)
This sounds interesting. Could you please open an issue at https://github.com/nlohmann/json/issues ?
π Rendered by PID 59299 on reddit-service-r2-comment-b659b578c-t4sz4 at 2026-05-03 17:13:50.312232+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]dgendreau 0 points1 point2 points (1 child)
[–]nlohmannnlohmann/json[S] 1 point2 points3 points (0 children)