@Webmaster4o Quoting directly from the pickle docs:
Comparison with json
There are fundamental differences between the pickle protocols and JSON (JavaScript Object Notation):
- JSON is a text serialization format (it outputs unicode text, although most of the time it is then encoded to utf-8), while pickle is a binary serialization format;
- JSON is human-readable, while pickle is not;
- JSON is interoperable and widely used outside of the Python ecosystem, while pickle is Python-specific;
- JSON, by default, can only represent a subset of the Python built-in types, and no custom classes; pickle can represent an extremely large number of Python types (many of them automatically, by clever usage of Python’s introspection facilities; complex cases can be tackled by implementing specific object APIs).
The last point may answer your question. JSON can only serialize a number of standard types, pickle can serialize just about anything.
Also, try to save this simple data structure as JSON:
parent = {'name': 'foo', 'children': []}
child = {'name': 'bar', 'parent': parent}
parent['children'].append(child)
json_str = json.dumps(parent) # This won't work
Even though it consists solely of standard types (dict, list, str), calling json.dumps(parent) will fail because of the circular references. You can of course represent this as JSON, but it requires quite a bit of extra work, and you need to think about how to represent your data in a way that is JSON-serializable. pickle.dumps(parent), on the other hand, just works.
This isn't to say you should use pickle in cases where JSON does what you need (you probably shouldn't actually), just to show that it's not as useless as you might think. ;)