I send JSON data with socket in Python:
{"receiver": "2", "sender:": 1, "seq_num": 10, "data": "{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}"}
Here is the data that I send. And it is string type, because I couldn't use sendall for JSON type.
And when I receive it, I tried to make that string into JSON. So I did,
data = client_socket.recv(1024)
#data = json.loads(data)
data = json.loads(json.dumps(data))
I got this error:
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 59 (char 58)
There's a syntax error in your data
field. By putting it in as "{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}"
, the double quotes mess up the encoder, causing it to throw an error.
If you wanted to value to be an object, you can simply remove the enclosing quotes like so:
data = {"receiver": "2", "sender:": 1, "seq_num": 10, "data": {"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}}
However, if you want it to be a string, then you have to make all of the double quotes inside escaped like this:
{
"receiver": "2", "sender:": 1, "seq_num": 10,
"data": "{\"iv\": \"jdjhvwGriJ95kZwgDWlShw==\", \"ciphertext\": \"Fg7ugYYAnPzL+lG8d7QDDA==\"}"
}