Improved JSON Encoding #220
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why: There are a lot of advantages to returning a slightly richer python object as opposed to simply a dictionary or string. Say perhaps, you are returning objects that will be tracked by an ORM or you are returning simple data classes.
What: Leverages a simple enhanced JSON encoder class that handles dataclasses, datetimes, and an
__html__
method. This is copy of the implementation for flask https://github.com/pallets/flask/blob/f61172b8dd3f962d33f25c50b2f5405e90ceffa5/src/flask/json/provider.py#L108How: Adds a DefaultJSONEncoder to the tools orchestration that is passed into
json.dumps
. This also enables users to override the default if needed.I have run
pre-commit
and I have run most of the test suite but a small subset of the provider tests I am not able to run.Thanks really great library that I use a lot.