3 ms·
JSON, while a fantastic lightweight data format, is insufficient for storing even moderately complex objects. It can not properly differentiate between tuples a
by falcolas 13y ago
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 you want anything other than an object, array, string or number.
Unless I'm dealing with untrusted data sources, or need to interoperate with other languages, I will keep using Pickle.
- deleted 13y ago[deleted]
- boronine 13y agoI built an extensible type system on top of JSON for serialization and validation. Among other types, it ships with DateTime (it represents dates as ISO strings). It also lets you define your own types, as simple or complex as you need them to be. If you've got a minute to take a look, I would really appreciate some feedback :) http://www.cosmic-api.com/docs/teleport/python/latest/ http://www.cosmic-api.com/docs/teleport/python/latest/
- drdaeman 13y agoHeh. 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 https://pypi.python.org/pypi/dill
- dman 13y agoAlso Dill's developer Michael Mckerns is super responsive and helpful. Hopefully someday pickle will be replaced / augmented with dill in the standard distribution.
- brianpgordon 13y agoAlso, most critically, JSON doesn't allow circular references.