✨ Add SimpleJSONResponse for decimal JSON encoding#5023
✨ Add SimpleJSONResponse for decimal JSON encoding#5023tomy0000000 wants to merge 5 commits intofastapi:masterfrom tomy0000000:master
SimpleJSONResponse for decimal JSON encoding#5023Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5023 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 532 533 +1
Lines 13672 13740 +68
=========================================
+ Hits 13672 13740 +68 ☔ View full report in Codecov by Sentry. |
|
Maybe you can make some tests and write some docs too |
|
Hi folks, as suggested, I've written a page detailing on how to make use of This is my first time authoring a complete doc for open source project, feedbacks are welcomed 👍🏻 |
odiseo0
left a comment
There was a problem hiding this comment.
media_type = "application/json" is not necessary and also you need to write tests
|
I could really use this ASAP. Any chance this will get merged soon? |
|
@tiangolo Would you mind taking a minute to review this? Docs and tests ready, reviewed by others. |
|
Thank you @tomy0000000! 🍰 Nevertheless, instead of providing another type of response, I prefer to teach people how to create their own, in particular when creating a new response takes an effort equivalent to learning a new one included, also as not everyone will need it, but if it's included, everything learning could expect to need to learn it. And as it's around 2 or 3 lines of code, I prefer to teach how to use it: https://fastapi.tiangolo.com/advanced/custom-response/#custom-response-class But you could, for example, write a blog post about using decimal values in JSON responses with your use case, and how to create the For now, I'll pass on this one, but thanks for the effort! ☕ |
|
Can i get a link to the doc? I need some help where Decimals need to serialize as JSON numbers with trailing zeroes intact. |
As mentioned in #4998. I believe
simplejsonis the best option to accomplish high decimal points real number encoding, hence the need ofSimpleJSONResponse. I followed some of the parameters used instarlette's originalJSONResponsehere to make sure the output are the most consistent as possible.If interested, I'm also willing to draft a page of doc detailing the best practice of handling decimal in FastAPI I've come up so far. Just let me know if that's something you'd like to include.