Python Forum
Flask TypeError: Object of type Decimal is not JSON serializable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Flask TypeError: Object of type Decimal is not JSON serializable (/thread-34285.html)



Flask TypeError: Object of type Decimal is not JSON serializable - mekacharan - Jul-15-2021

We are using flask for our application service. Internally we are using Jsonify to return the respon[img]se and our response contains decimal data.

Couple of things to mention here.

1) We are using Windows machine

2) Some of my colleagues, they are not getting any issue with the data with same configuration. One thing we observed is flask by default uses simplejson if installed. If not, then it will fall back to json package.

Sample data : jsonify({'response':Decimal('12345.00000')})

Our question is why for some people flask by default using simplejson and for others it's not able to identify simplejson(even though installed) and using only json throwing decimal json error.

Any idea what might be the root cause and what change needs to be done, let flask know to use simplejson over json ?

For time being we did below manual change in flask package.

Manual Change to let flask take simplejson

[Image: ko2Ep.png]