From 9fdb72cc5c69138d19c969d9cef91c5f60cd6bd0 Mon Sep 17 00:00:00 2001 From: Brian Painter Date: Wed, 23 Mar 2016 08:21:36 -0400 Subject: [PATCH] if the object is a decimal, return the string representation of it. --- tablib/formats/_json.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tablib/formats/_json.py b/tablib/formats/_json.py index 777040a..d063d10 100644 --- a/tablib/formats/_json.py +++ b/tablib/formats/_json.py @@ -2,6 +2,7 @@ """ Tablib - JSON Support """ +import decimal import tablib @@ -14,7 +15,13 @@ extensions = ('json', 'jsn') def date_handler(obj): - return obj.isoformat() if hasattr(obj, 'isoformat') else obj + if isinstance(obj, decimal.Decimal): + return str(obj) + elif hasattr(obj, 'isoformat'): + return obj.isoformat() + else: + return obj + # return obj.isoformat() if hasattr(obj, 'isoformat') else obj def export_set(dataset):