On Wed, 28 Aug 2019 03:03:00 +0900 "Stephen J. Turnbull" email@example.com wrote:
Antoine Pitrou writes:
Here is a use case where it may remove some pain from users'life: https://bugs.python.org/issue24313
The problem is that a protocol like __json__ doesn't help in deserializing, so you either can't use json.loads(), or more likely you'll need to have a post-parser to rebuild the objects.
If you have a use case where you need to recreate the data, in a Python interpreter, in the exact original form, then sure, use pickle. But JSON is commonly used where you transport data to some other runtime, or at least to an endpoint which only cares about JSON-transportable semantics; there the difference between a "Python int", a "Numpy int8", a "Numpy uint32"... needn't apply, because the receiver needn't care.
And it actually doesn't help as much as you'd hope in serializing, either, not for a decade or so, because most objects won't have a __json__ method.
By the exact same reasoning, you can believe JSON "doesn't help very much" because most Python objects don't serialize with it. There's no point in discussing such stupid and out-of-touch arguments.