No description provided.
JSONEncoder cast Decimal to string
Why do you think this is the way to go?
Flask-Restless makes use of it and it could help if it handled decimals too.
Not sure if this is proper, I'm opened to suggestions :)
I think use float instead of str is better, eg, Decimal(0.123) converted to string is not good for normal usage.
Cast Decimal to float
There is no way to generally describe decimal numbers in JSON, which is why I think this shouldn't be done by Flask. Especially if there is no way to decode.
Why do you say there is no way to describe decimal numbers in JSON? Looking at the language specification at json.org, it appears to deal with decimals (as floats) fine. Returning a Decimal as a float appears to be the correct behavior according to the spec.
@chason but when you decoding that value, you got a float, rather than decimal.Decimal, interoperability is lost
I've seen that floats are often "encoded" as strings in JSON-based APIs but i don't know why.
I think if your application need to return a decimal, you should always find a way to keep the precision, it's better leave this to developer instead of the framework.
Closing this. String would be the correct thing but that's by far not the only way to represent decimals.