I am running an SQL query which returns a list of Decimals. When I try to convert this into JSON i get the type error.
The query:
res = db.execute("""
SELECT CAST ((SUM(r.SalesVolume)/1000.0) AS decimal(6,1))
FROM RawData r
INNER JOIN Product p
ON r.ProductId = p.ProductId
INNER JOIN Calendar c
ON r.DayId = c.DayId
WHERE c.WeekCodeInYear BETWEEN 1 AND 12
AND
c.YearId = 2014
GROUP BY c.WeekCodeInYear """)
Result List:
[Decimal('34.3'), Decimal('50.9'), Decimal('31.5'), Decimal('23.3'), Decimal('19
.7'), Decimal('56.9'), Decimal('43.8'), Decimal('35.2'), Decimal('29.2'), Decima
l('43.7'), Decimal('42.6'), Decimal('23.4')]
Code:
for row in res:
testlist.append (row[0])
print testlist
list = json.dumps(testlist)
And the I get the Unable to serialize error
Tried looking up online, no much help.
Please note that the final list would go as input data to a chart.