loading...

Convert a string to json object properly

lucpattyn profile image Mukit, Ataul ・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 (https://github.com/nlohmann/json).
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;

}

Discussion

markdown guide