JSON, while a fantastic lightweight data format, is insufficient for storing even moderately complex objects. It can not properly differentiate between tuples and lists, it can only accept strings for object keys, and it only stores unicode strings. You also have to write custom (de)serializers if you want to store datetime objects (my personal pet peeve), any of the special python containers... basically any time yo…
Don't Pickle Your Data
21–26 of 26 posts
Re: Don't Pickle Your Data
#22JSON, while a fantastic lightweight data format, is insufficient for storing even moderately complex objects. It can not properly differentiate between tuples and lists, it can only accept strings for object keys, and it only stores unicode strings. You also have to write custom (de)serializers if you want to store datetime objects (my personal pet peeve), any of the special python containers... basically any time yo…
Heh. Pickle is not really sufficient for some edge cases, too. Luckily, there's Dill that can take almost perfect snapshots of the whole interpreter: https://pypi.python.org/pypi/dill
Re: Don't Pickle Your Data
#23Disagree strongly. You have no idea how complex my graphs of (pretty damn complex) python objects are and how much I value being able to change their organization without having to rewrite the serialization code every time I do so.
Don't fear pickle. Just don't expect it to be secure or amazingly fast.
Re: Don't Pickle Your Data
#24In case anyone doesn't know, Python has had a json library since version 2.6.
Re: Don't Pickle Your Data
#25I thought pickle output was just JSON? Shows what I know.
If it was JSON, how would you pickle dictionaries with tuples as keys?
For a fully general python json serializer/deserializer, you'd need a bunch of extra annotations etc that would make it look very weird compared with what most people expect when they think of json.