Hi !
>From a controller, I am trying to return a jsonified resultset (obtained by 
executing sql directly).

resultset = ( ('201207020920', Decimal('5308.20'), Decimal('5308.20'), 
Decimal('5288.00'), Decimal('5292.40'), ...)

## convertd it to list of lists

list_of_tuples = list(resultset)
list_of_lists = [list(i) for i in list_of_tuples]

## Since an error is thrown as under--

TypeError: Decimal('5308.20') is not JSON serializable


## convertd all list items decimal to str ---

for x in list_of_lists:
        for y in x:
            y = str(y)
            print y, 'type of this y is ', type(y)

## confirmed that all are of type 'str'

D = dict(list_of_lists = list_of_lists)
return response.json(D)

Still, the same error is thrown as under--

TypeError: Decimal('5308.20') is not JSON serializable

How do I fix this?

Thanks,

Vineet

Reply via email to