So I want to turn a string into a JSON object but I'm not sure how. I'm using the Nlohmann library.
This is my string called "readBuffer":
{"sscresponse":{"errorcode":0, "errordesc":"-","data":{"pac_power_wr_kwh":"6.374","pac_power_all_wr_kwh":"6.622","voltage_ac_volt":"59","voltage_dc_volt":"673","daily_output_kwh":"6.904","yesterday_output_kwh":"0","monthly_output_kwh":"6.904","yearly_output_kwh":"25883.4","total_output_kwh":"296533","current_consumption_kwh":"0","daily_consumption_kwh":"0","yesterday_consumption_kwh":"0","monthly_consumption_kwh":"0","yearly_consumption_kwh":"0","sum_of_all_consumers_kwh":"0","installed_generator_power_kwp":"100"}}}
I've tried it like this:
json j2 = R"(
{
"happy": true,
"pi": 3.141
}
)"_json;
j2 = readBuffer;
std::string s = j2.dump();
std::cout << j2.dump(15) << std::endl;
This is the OUTPUT:
"{\"sscresponse\":{\"errorcode\":0, \"errordesc\":\"-\",\"data\":{\"pac_power_wr_kwh\":\"6.374\",\"pac_power_all_wr_kwh\":\"6.622\",\"voltage_ac_volt\":\"59\",\"voltage_dc_volt\":\"673\",\"daily_output_kwh\":\"6.904\",\"yesterday_output_kwh\":\"0\",\"monthly_output_kwh\":\"6.904\",\"yearly_output_kwh\":\"25883.4\",\"total_output_kwh\":\"296533\",\"current_consumption_kwh\":\"0\",\"daily_consumption_kwh\":\"0\",\"yesterday_consumption_kwh\":\"0\",\"monthly_consumption_kwh\":\"0\",\"yearly_consumption_kwh\":\"0\",\"sum_of_all_consumers_kwh\":\"0\",\"installed_generator_power_kwp\":\"100\"}}}"
I want it to be displayed like a normal JSON object:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
Could somebody help?