Opened 9 years ago
Closed 9 years ago
#25254 closed New feature (fixed)
Allow control over json.dumps keyword arguments in JsonResponse
Reported by: | Jaap Roes | Owned by: | Sambhav Satija |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | json dumps indent separators jsonresponse |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently JsonResponse
's only allows changing the JSON encoder class. It would be helpful to allow some/all of the arguments to json.dumps
.
In my case I've had the need to set indent=2
, to get a more readable output, and separators=(',', ':')
to get the most compact output possible. Having control over allow_nan
or skipkeys
could also be useful for some.
Change History (7)
comment:2 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 9 years ago
Maybe it would make sense to add a parameter: json_dumps_options=None
which could be a dictionary of options.
comment:4 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Going to add parameter which would take in dictionary and pass kwargs
as suggested by timgraham.
comment:6 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Looks okay, pending a few cosmetic issues.
A partial workaround for this is to create a custom encoder class that sets the desired values for
indent
andseparators
, this won't work as well for otherkwargs
as there are defaults set indumps
.