ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.43k stars 889 forks source link

JSON parser response #364

Open Shriyanshmit opened 4 years ago

Shriyanshmit commented 4 years ago

I want inner JSON object please let me know how I can create the same as mentioned below. I tried with below code. Please help this code is throwing error.

// simple json response CROW_ROUTE(app, "/json") ([]{ crow::json::wvalue x; x["Status"] = true; x["ErrorMessage"] = "No Error";

    crow::json::wvalue y;  
    y["IsValidUser"] = true;
    y["Prop2"] = "No Error";        

    x["ResponseData"] = y;

        return x;       
}); 

I want the same response as mentioned below.

{"ResponseData":{ "IsValidUser":true,"Prop2":"No Error"},"Status":true,"ErrorMessage":"No Error"}

The-EDev commented 3 years ago

I use jsoncons, it's way simpler than crow::json, although you do need to set_header("Content-Type", "application/json") and dump the json string into the response body.