[Django] #25254: Allow control over json.dumps keyword arguments in JsonResponse

5 views
Skip to first unread message

Django

unread,
Aug 10, 2015, 5:12:29 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------+-------------------------------------------------
Reporter: jaap3 | Owner: nobody
Type: New | Status: new
feature |
Component: HTTP | Version: master
handling | Keywords: json dumps indent separators
Severity: Normal | jsonresponse
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25254>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 10, 2015, 5:22:53 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage:
separators jsonresponse | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jaap3):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:1>

Django

unread,
Aug 10, 2015, 8:56:25 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: nobody

Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage: Accepted
separators jsonresponse |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:2>

Django

unread,
Aug 10, 2015, 10:17:21 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: nobody

Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage: Accepted
separators jsonresponse |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Maybe it would make sense to add a parameter: `json_dumps_options=None`
which could be a dictionary of options.

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:3>

Django

unread,
Aug 10, 2015, 10:59:09 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: darkryder
Type: New feature | Status: assigned

Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage: Accepted
separators jsonresponse |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by darkryder):

* owner: nobody => darkryder
* status: new => assigned


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:4>

Django

unread,
Aug 10, 2015, 11:41:35 AM8/10/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: darkryder
Type: New feature | Status: assigned
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage: Accepted
separators jsonresponse |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by darkryder):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/5127

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:5>

Django

unread,
Aug 11, 2015, 10:21:04 AM8/11/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: darkryder
Type: New feature | Status: assigned
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: json dumps indent | Triage Stage: Ready for
separators jsonresponse | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


Comment:

Looks okay, pending a few cosmetic issues.

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:6>

Django

unread,
Aug 12, 2015, 10:45:52 AM8/12/15
to django-...@googlegroups.com
#25254: Allow control over json.dumps keyword arguments in JsonResponse
-------------------------------------+-------------------------------------
Reporter: jaap3 | Owner: darkryder
Type: New feature | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: json dumps indent | Triage Stage: Ready for
separators jsonresponse | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d0bd5330432e1dda519ebd89606bd0980a36dcb4" d0bd533]:
{{{
#!CommitTicketReference repository=""
revision="d0bd5330432e1dda519ebd89606bd0980a36dcb4"
Fixed #25254 -- Added JsonResponse json_dumps_params parameter.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25254#comment:7>

Reply all
Reply to author
Forward
0 new messages