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:1 by Jaap Roes, 9 years ago

A partial workaround for this is to create a custom encoder class that sets the desired values for indent and separators, this won't work as well for other kwargs as there are defaults sets in dumps.

Version 0, edited 9 years ago by Jaap Roes (next)

comment:2 by Claude Paroz, 9 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 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 Sambhav Satija, 9 years ago

Owner: changed from nobody to Sambhav Satija
Status: newassigned

Going to add parameter which would take in dictionary and pass kwargs as suggested by timgraham.

comment:6 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

Looks okay, pending a few cosmetic issues.

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In d0bd533:

Fixed #25254 -- Added JsonResponse json_dumps_params parameter.

Note: See TracTickets for help on using tickets.
Back to Top