Serhiy Storchaka added the comment: The json module already has too many options. No need for yet one such specialized.
>>> class number_str(float): ... def __init__(self, o): ... self.o = o ... def __repr__(self): ... return str(self.o) ... >>> def decimal_serializer(o): ... if isinstance(o, decimal.Decimal): ... return number_str(o) ... raise TypeError(repr(o) + " is not JSON serializable") ... >>> print(json.dumps([decimal.Decimal('0.20000000000000001')], >>> default=decimal_serializer)) [0.20000000000000001] You can extend this to support complex numbers, fractions, date and time, and many other custom types. Have specialized options for this would be cumbersome. ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16535> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com