Skip to content

[feature request] std::string support for json libraryΒ #72

@petke

Description

@petke

In my experience most 3rd party libraries use std::string and not std::wstring in their interface. Therefore applications become tied to std::string. Because the ppl/json library uses std::wstring (on windows) this makes integrating the ppl/json library into an applications cumbersome and inefficient. One has to do lots of unnecessary wstring-to-string and string-to-wstring conversions. Could you add support for std::string, at least for the json library?

Minimal example:

    #include <cpprest/json.h>

    std::string SerializeToJson(std::string name, int id) //utf8 coming in and goin out
    {
        utility::stringstream_t stream;
        web::json::value js_obj;
        js_obj[L"id"] = web::json::value::number(id);
        js_obj[L"name"] = web::json::value::string(utility::conversions::utf8_to_utf16(name)); //unneccessary conversion 1

        js_obj.serialize(stream);
        std::wstring wret = stream.str();
        std::string ret = utility::conversions::utf16_to_utf8(wret); //unneccessary conversion 2

        return ret;
    }

    int main() {

        auto r = SerializeToJson("test", 123);
        std::cout << r << std::endl;
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions