'Cannot parse json sent via websockets

I'm trying to send a JSON packet to my server but everything I've tried doesn't work (mainly different variations of putting the JSON into a buffer.

The server is receiving the packet as follows

"{\"content\":{\"secret\":\"72F51AB05A1A104C6D72F51AB0ADE3645CDD40A74A7A8F3BE606D01922ACC1D2\"},\"status\":\"c5479d466aec26e14f30bce9923a3b5322af2c1ed609a68e19b0f9c16554bc89\",\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOnRydWUsInN0YXR1cyI6IlZhbGlkIExpY2VuY2UiLCJsaWNlbmNlIjoiTFlFSkM1elNUNXVoIiwiY29udGVudCI6eyJyb2xlIjp7Im5hbWUiOiJVc2VyIiwiYmFubmVkIjpmYWxzZX0sImV4cGlyeSI6MTY0MzE1Nzk1NjM5OX0sImlhdCI6MTY0MzY4Nzg5NywiZXhwIjoxNjQzNzc0Mjk3fQ.Rjap3_Z43wvYrGOemMn79lh9R6_mk9-xWv5OVJYduXc\"}"

I have also put this packet through a json debugger where it didn't run into any issues. The error Im getting from my server is

Error reading json: EOF while parsing a value at line 1 column 0

So interpreting this error it makes me believe the " at the start of the JSON is throwing it off. So I've looked to how the client is sending the JSON packet to the server.

This is where the server handles the incoming packets

pub fn new(content: &Message) -> Result<Self, Box<dyn Error>> {

    let text = match content.to_text() {
        Ok(txt) => txt,
        Err(err) => return Err(Box::new(err)),
    };
  
    println!("{:?}", text);

    match serde_json::from_str::<Packet>(text) {
        Ok(packet) => return Ok(packet),
        Err(err) => return Err(Box::new(err)),
    }
}

This is the client implementation, I'm using boost-beast's websockets which I have tried to configure in various ways like setting the content type and setting the options (ws.binary, ws.true); I have removed the changes made so that the code can pertain or closely resemble the boost-beast example

try {
    auto const results = resolver.resolve(xorstr_("127.0.0.1"), xorstr_("3001"));
    net::connect(ws.next_layer(), results.begin(), results.end());

    ws.set_option(websocket::stream_base::decorator(
        [](websocket::request_type& req)
        {
            req.set(http::field::user_agent,
                std::string(BOOST_BEAST_VERSION_STRING) +
                xorstr_(" websocket-client-coro"));
        }));

    ws.handshake(xorstr_("127.0.0.1"), xorstr_("/"));

    json packet;
    packet[xorstr_("content")][xorstr_("secret")] = packets::jwtsecret;
    packet[xorstr_("status")] = packets::jwt;
    packet[xorstr_("token")] = token;

    ws.write(boost::asio::buffer(
        packet.dump()));
}
catch (std::exception& e) {
    printf("%s\n", e.what());
    return false;
}

The server is written in Rust and the client is in C++ using Nlohmann for the JSON implementation, at this point I don't know what could be wrong I've searched for answers but have gone without luck so far so any potential fixes would be awesome as this project is starting to fade away for me and I really want to resolve this, thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source