Closed deepio-oc closed 2 years ago
Hi deepio-oc, sorry for the late reply, I have been on summer leave. I am not sure whether I understand your issue properly. What you pass in as data is in your responsibility, so I would assume you need to take care of proper serialisation. If I am missing something, please reopen.
if self.data is dictionary object, str(self.data) does not generate a compliant json string. It is converting to string using single quotes for the key and values (e.g "{'key':'value'}"). JSON.parse in the browser can not load this string back to dictionary object.
Yes, deepio-oc right When I transfer json data, in ServerSentEvent.encode the dictionary turns into a string, but I want to transfer json file :(
@pavlo-yashchuk dictionary need to be encoded as string before it is sent. On the receiver side, you need to decode it back to json object from string.
my issue is that encoded string format is not JSON compliant and I cant decode it back.
@sysid I dont see any option to open this ticket.
Okay) but I found solution for me add json loads before dumps
I don't think this should be marked closed. Converting dicts to valid JSON seems like a reasonable task for the library to handle, and not a particularly hard feature to add. For example, right now simple code like this won't work.
I agree that converting a dict to valid JSON is something I would expect the library to take care of. I've added a PR to address this here: #79
I am trying to send a dictionary object to the browser but JSON.parse fails on browser side saying single quotes are not allowed.
The issue is with the following code, which tries to convert dictionary to string (resulting in single quotes).
Could you check the data type and may use json.dumps or provide it as configuration option?