Convert a string to json object properly

・1 min read

Some of us ran into problem when it came to converting a std::string or a const char* string properly to json object by nlohmann (
Here is how I achieved it :

#include <string>
#include <iostream>>
#include <sstream>

#include "json.hpp"
using namespace nlohmann;

json toJson(const char* jsonString){
    json jsonObj;
    std::stringstream(jsonString) >> jsonObj;

    return jsonObj;


Classic DEV Post from Aug 31 '18

How do you stop the desire to learn too much?

Example: While you are learning a specific thing ( language, framework, new tec...

I consider myself as an enthusiast in learning new things everyday, about our history and future as well as the present. My interests: Ancient History, Comparative Religion, Science and Tech, C++

Sore eyes? now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️