Ticket #3324: 3324_Decimal_is_not_JSON_serializable.diff

File 3324_Decimal_is_not_JSON_serializable.diff, 776 bytes (added by eric@…, 18 years ago)
  • django/utils/simplejson/encoder.py

     
    22Implementation of JSONEncoder
    33"""
    44import re
     5from decimal import Decimal
    56
    67ESCAPE = re.compile(r'[\x00-\x19\\"\b\f\n\r\t]')
    78ESCAPE_ASCII = re.compile(r'([\\"/]|[^\ -~])')
     
    256257            yield 'false'
    257258        elif isinstance(o, (int, long)):
    258259            yield str(o)
    259         elif isinstance(o, float):
     260        elif isinstance(o, float) or isinstance(o, Decimal):
    260261            yield floatstr(o, self.allow_nan)
    261262        elif isinstance(o, (list, tuple)):
    262263            for chunk in self._iterencode_list(o, markers):
Back to Top