Python Forum
Flask TypeError: Object of type Decimal is not JSON serializable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask TypeError: Object of type Decimal is not JSON serializable
#1
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 1,117 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 892 May-11-2020, 04:58 PM
Last Post: jenkins43
  Flask rest api How to retrieve json request raysefo 4 4,144 Jan-20-2019, 06:46 PM
Last Post: raysefo
  AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask) usman 0 3,317 Nov-20-2018, 09:50 PM
Last Post: usman
  500 error cannot deserialize json object SaiBhargav 0 1,700 Sep-18-2018, 09:53 PM
Last Post: SaiBhargav
  Paginate json data in flask or jinja2 soli1994 1 6,061 Jun-28-2018, 06:00 PM
Last Post: gontajones
  flask, I want to send a json from the front end and update it to the postgresql DB wi passion044 1 2,829 Apr-12-2018, 08:40 AM
Last Post: thomasp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020