0

I am fetching data from db using raw SQl queries , I am following these django docs. As you can see in django docs we have a function dictfetchall which returns dict with field names and values. I am converting this dict to json as per my requirements but as you can see in output cursor return values with unicode like

> 54360982L
> for date - datetime.date(2015, 8, 3)
> for decimal - Decimal('0.63')

Thus dict cannot be convert into json as it will raise error Decimal('0.63') is not JSON serializable . So How i can prevent raw sql to sent simple values from db or need to edit dictfetchall function , if yes then where ?

saf
  • 259
  • 4
  • 20
  • Possible duplicate of http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object – Tanveer Alam Aug 06 '15 at 06:14
  • @TanveerAlam But its only for Decimal , you know json will create issues for others too like Date – saf Aug 06 '15 at 06:33
  • You can make your datetime also in string format http://stackoverflow.com/questions/2158347/how-do-i-turn-a-python-datetime-into-a-string-with-readable-format-date – Tanveer Alam Aug 06 '15 at 11:42

0 Answers0