If you want to get encoding and decoding data without doing it, you can use json_tricks , which is a wrapper that adds encoding and decoding for various popular types. Just install:
pip install json_tricks
and then import from json_tricks instead of json , for example:
from json_tricks import dumps, loads json = dumps({'name': 'MyName', 'birthday': datetime.datetime(1992, 5, 23, 18, 38, 23, 37566)}) me = loads(json)
Disclaimer: This is done by me. Because I had the same problem.
If you want to automatically serialize anything that can be compressed, you can do this with the standard implementation very easily:
dumps(obj, default=str)
But note that this has disadvantages, for example. none of them will be deserialized without extra effort, and maybe sometimes you just donβt want to serialize anything (for example, a large numpy array function), but instead get a warning that will be disabled by this method.
Mark Oct 19 '16 at 21:51 2016-10-19 21:51
source share