-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jsonify a Decimal #835
Comments
I should add that I have simply been converting the Decimal with str(Decimal) before passing it into jsonify and that is currently working, but it's ugly. |
If you use simplejson, it includes Decimal encoding by default. |
I will try that instead of jsonify. Is there anything jsonify does that is specifically beneficial vs simplejson? |
If you install the simplejson package, flask.jsonify will automatically use On Wed, Aug 14, 2013 at 3:54 PM, michaelfillier notifications@github.comwrote:
|
Oh, that's great! Thanks. |
Cost was returning a `Decimal`, which jsonify doesn't like. Making it a float fixes the problem. [Relevant issue on github](pallets/flask#835).
I will add that simplejson does not do datetime objects, while the default JSONEncoder does. |
@mrwillis Flask's json encoder uses simplejson when available. If something is not working, please report a new issue with an example. |
I ran into this today |
|
To further extend it, you can override |
Currently getting a TypeError: Decimal('0.10') is not JSON serializable error when, you guessed it, I try to encode a Decimal.
I found an accepted fix here: http://stackoverflow.com/questions/4019856/decimal-to-json, but not sure where I should be implementing that within Flask. I tried it within my main app file, but it doesn't appear to be working.
The text was updated successfully, but these errors were encountered: