HI:
This might give you a start:
import simplejson
class FancyEncoder(simplejson.JSONEncoder):
"""
Handle datetime objects.
"""
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
# Add more type-specific handlers here, for example for Decimals
return simplejson.JSONEncoder.default(self, obj)
json = simplejson.dumps(data_to_encode, cls=FancyEncoder)
As you can see it replaces the datetimes with their ISO format
representations as strings.
Hope this helps,
Domhnall.
2009/4/30 Uwe Feldtmann <[email protected]>
> Hi all.
>
> I've been struggling with a controller that gets a result set from a
> database and should simply return that result set as json data and I keep
> getting this traceback
>
> TypeError: Decimal("0.00") is not JSON serializable
>
> the data returned from the db is:
> (1492, 'BAKER', 'MR. AND MRS BAKER', Decimal("843.50"), Decimal("5000.00"),
> Decimal("0.00"), datetime.date(1998, 8, 24), datetime.date(1998, 8, 31))
>
> Is this an issue with @jsonify or am I missing something?
>
>
> I am using simplejson-2.0.8 and py2.5
>
> Thanks in advance.
>
> >
>
--
Quidquid latine dictum sit, altum sonatur.
(Whatever is said in Latin sounds profound)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---