Unity & API Gateway - How to send a websocket action?

HI all, first post!

I am building a little multiplayer game using all serverless AWS services in the backend (API Gateway, Lambda, DynamoDB, etc.). I’m not a software engineer by training, so I hit roadblocks more often than I'd like to admit.

I have encountered problems with trying to send actions to AWS API Gateway using a Websocket connection. Whenever I attempt to send a json string, it comes out the other end with the \" backouts (e.g. "body": "{\"action\":\"get_player_status\",\"username\":\"asdasd\"}"). API Gateway is unable to parse this and always calls the $default action. I have tried different approaches to combat this, but without success. Right now I have a Lambda Python function that takes all messages, corrects the json string, then forwards it to the correct Lambda function. This is basically doing what API Gateway is supposed to do, but with much higher latency and cost.

Any ideas?

Code snippet:

using NativeWebSocket;

public class SendAction
    public string action;
    public string username;

void GetPlayerStatus()
    SendAction getStatus = new SendAction();
    getStatus.action = "get_player_status";
    getStatus.username = username;

    string jsonGetStatus = JsonUtility.ToJson(getStatus);


Solved by using Newtonsoft.json to hand it.

string json = JsonConvert.SerializeObject(body, Formatting.Indented);