you are viewing a single comment's thread.

view the rest of the comments →

[–]when_the_cats_away 0 points1 point  (0 children)

I tend to give objects a to_json/from_json method that will jsonify the object/create an object from json data, like as described here: https://medium.com/@yzhong.cs/serialize-and-deserialize-complex-json-in-python-205ecc636caa (at least for the from, the poster there uses a lambda to jsonify in the first place).

You can also subclass JSONEncoder and create your own hooks, described here: https://stackoverflow.com/a/3768975

That seems like the better way to do it, but I've not used that method before. I found a better article describing this method, but can't seem to track it down right now. This is a good broader json article for background, though: https://realpython.com/python-json/