4 ms·
The author understates the problem. Many half-baked solutions handle serializing, but don't consider how you're going to deserialize data. And if you do anythin
by ben509 6y ago
The author understates the problem. Many half-baked solutions handle serializing, but don't consider how you're going to deserialize data. And if you do anything with numbers, you may need to guard against intermediate processors that truncate all numbers to 64-bit float accuracy.
I took a shot at it with https://pypi.org/project/json-syntax/ https://pypi.org/project/json-syntax/ after doing some ad hoc solutions.
My approach was:
1. Don't serialize directly to JSON, but convert to the "jsonic" types.
2. Allow users to pick the rules they need, and make it reasonably easy to create new rules.
3. Generate picklable encoding and decoding functions.
It's worked pretty well for a project that has a very complex set of objects that need to be transmitted via JSON. The main difficulty is that it depends on interrogating Python's type annotations, which were pretty sketchy in earlier versions.