This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients eric.araujo, ezio.melotti, pitrou, rhettinger, serhiy.storchaka, skrah
Date 2012-11-23.09:32:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1353663176.04.0.304458206702.issue16535@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-11-23 09:32:56serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, pitrou, ezio.melotti, eric.araujo, skrah
2012-11-23 09:32:56serhiy.storchakasetmessageid: <1353663176.04.0.304458206702.issue16535@psf.upfronthosting.co.za>
2012-11-23 09:32:56serhiy.storchakalinkissue16535 messages
2012-11-23 09:32:55serhiy.storchakacreate