DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,200 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Mukit, Ataul
Mukit, Ataul

Posted on

Convert a string to json object properly

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;

}

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.