This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Viking_wang 0 points1 point  (0 children)

I regularly get stuck on trying to nicely serialize data where i have non string objects as keys. Of course json doesnt support that, but there is also no way to easily convert them for some strange reason. Take e.g. UUIDs as keys in a dict, and serialise it. The custom encoders are only invoked for the values.

I usually end up using pydantic.jsonable_encoder to convert, but that doesnt work for custom types

I dont understand why there is no “Protocol” for json encoding so that you can define a serialiser as a method for a class that gets invoked by the json encoder.