[Django] #27415: Add request.JSON or request.get_json()

16 views
Skip to first unread message

Django

unread,
Nov 1, 2016, 7:35:36 PM11/1/16
to django-...@googlegroups.com
#27415: Add request.JSON or request.get_json()
-------------------------------------+-------------------------------------
Reporter: Ustun | Owner: nobody
Ozgur |
Type: New | Status: new
feature |
Component: Core | Version: 1.10
(Serialization) | Keywords: json, request,
Severity: Normal | incoming data
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If the content-type is application/json, the body should be parsed and put
on request object as JSON or json field (or retrieved via a method like
get_json).

This is what flask does, and should be supported for convenience since it
is nowadays very common to ingest JSON.

I have seen several proposals in this regard, but those seem over generic
(ability to support multiple parsers etc.) and work on them seems to have
stalled or moved to libraries.

Solving the majority case where people use JSON should be good enough.

I have searched the open tickets, but haven't been able to find a
duplicate which just focuses on JSON.

https://code.djangoproject.com/ticket/21442

https://github.com/django/deps/blob/master/draft/content-negotiation.rst

https://flask.readthedocs.io/en/latest/api/#flask.Request.get_json

The json class might be configurable so that people can use ujson instead
of stock json for perf if needed.

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

Django

unread,
Nov 2, 2016, 9:39:36 AM11/2/16
to django-...@googlegroups.com
#27415: Add request.JSON or request.get_json()
-------------------------------------+-------------------------------------
Reporter: Ustun Ozgur | Owner: nobody
Type: New feature | Status: new

Component: Core | Version: 1.10
(Serialization) |
Severity: Normal | Resolution:
Keywords: json, request, | Triage Stage:
incoming data | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Hi Unstun,

Thanks for your suggestion but I believe we should focus on making
`request.data` available based on the `Content-Type` header like described
in the DEP you linked instead of adding a `JSON` attribute on request that
would be removed in the mid-term. In the meantime you can write a
middleware that adds a `JSON` attribute on request with the appropriate
content-type if you want to rely on that.

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

Django

unread,
Nov 2, 2016, 10:54:03 AM11/2/16
to django-...@googlegroups.com
#27415: Add request.JSON or request.get_json()
-------------------------------------+-------------------------------------
Reporter: Ustun Ozgur | Owner: nobody
Type: New feature | Status: closed
Component: HTTP handling | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: json, request, | Triage Stage:
incoming data | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => wontfix
* component: Core (Serialization) => HTTP handling


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

Reply all
Reply to author
Forward
0 new messages