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.
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
that instead of the stdlib json library.
On Wed, Aug 14, 2013 at 3:54 PM, michaelfillier [email protected]:
I will try that instead of jsonify. Is there anything jsonify does that is
specifically beneficial vs simplejson?—
Reply to this email directly or view it on GitHubhttps://github.com/mitsuhiko/flask/issues/835#issuecomment-22673774
.
Oh, that's great! Thanks.
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
$ pipenv install simplejson fixed :)
To further extend it, you can override Flask.json_encoder with your own subclass that handles more types.
Most helpful comment
If you install the simplejson package, flask.jsonify will automatically use
that instead of the stdlib json library.
On Wed, Aug 14, 2013 at 3:54 PM, michaelfillier [email protected]: