Greg Ewing wrote: > No, that's not the only way. It would be sufficient just to add a > "use decimal" option to the stdlib json module. > Since Python's Decimal preserves all the information in the JSON > representation of a float (including trailing zeroes!), anything > else you might want can be achieved by pre/postprocessing the > decoded data structure.
Actually it appeared to me that the best (for my case) would be to be able to store the original representation in the custom type as well (I am not sure if decimal.Decimal does that and cannot figure it right now) and then being able to use `dump_as_float` (discussed earlier) to define the custom float type for the serializer and then in the serializer function (e.g. `__str__`) return the original form from the input. This could be easily done by subclassing `decimal.Decimal` and implementing it in the subclass, then specifying this type in `json.load`'s `parse_float` argument and then pass the same type to `dump_as_float` of `json.dump`. This should resolve all the issues mentioned by Andrew, e.g: ``` In [7]: decimal.Decimal('1.0000E+3') Out[7]: Decimal('1000.0') ``` _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/D5XLP6MBGEHIQUDRYDT5GUIVATNEDV5F/ Code of Conduct: http://python.org/psf/codeofconduct/