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 eric.araujo
Recipients eric.araujo, ezio.melotti, pitrou, rhettinger
Date 2012-11-22.22:45:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1353624338.46.0.574343718645.issue16535@psf.upfronthosting.co.za>
In-reply-to
Content
In 2.7 and other versions, the json module has incomplete support for decimals:

>>> json.loads('0.2', parse_float=Decimal)
Decimal('0.2')
>>> json.dumps(json.loads('0.2', parse_float=Decimal))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 201, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 178, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: Decimal('0.2') is not JSON serializable

simplejson encodes decimals out of the box, but json can’t round-trip.
History
Date User Action Args
2012-11-22 22:45:38eric.araujosetrecipients: + eric.araujo, rhettinger, pitrou, ezio.melotti
2012-11-22 22:45:38eric.araujosetmessageid: <1353624338.46.0.574343718645.issue16535@psf.upfronthosting.co.za>
2012-11-22 22:45:38eric.araujolinkissue16535 messages
2012-11-22 22:45:37eric.araujocreate