Convert a string to json object properly

twitter logo ・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;


twitter logo DISCUSS
Classic DEV Post from Dec 1 '18

Let's talk about an unnecessary but popular Vue plugin

Do we really need a plugin for everything?

Mukit, Ataul profile image
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++

👋 Hey reader.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️