Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions django/http/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,15 +749,16 @@ class JsonResponse(HttpResponse):
:param encoder: Should be a json encoder class. Defaults to
``django.core.serializers.json.DjangoJSONEncoder``.
:param safe: Controls if only ``dict`` objects may be serialized. Defaults
to ``True``.
to ``False``.
:param json_dumps_params: A dictionary of kwargs passed to json.dumps().
"""

def __init__(
self,
data,
encoder=DjangoJSONEncoder,
# RemovedInDjango71Warning: Remove the safe parameter.
# RemovedInDjango71Warning: Remove the safe parameter from here and
# the docstring.
safe=None,
json_dumps_params=None,
**kwargs,
Expand Down
16 changes: 10 additions & 6 deletions docs/ref/request-response.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ can create it with the help of :class:`http.HTTPStatus`. For example::
``JsonResponse`` objects
========================

.. class:: JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, json_dumps_params=None, **kwargs)
.. class:: JsonResponse(data, encoder=DjangoJSONEncoder, safe=False, json_dumps_params=None, **kwargs)

An :class:`HttpResponse` subclass that helps to create a JSON-encoded
response. It inherits most behavior from its superclass with a couple
Expand All @@ -1239,14 +1239,22 @@ can create it with the help of :class:`http.HTTPStatus`. For example::
serialize the data. See :ref:`JSON serialization
<serialization-formats-json>` for more details about this serializer.

The ``safe`` boolean parameter defaults to ``True``. If it's set to
The ``safe`` boolean parameter defaults to ``False``. If it's set to
``False``, any object can be passed for serialization (otherwise only
``dict`` instances are allowed). If ``safe`` is ``True`` and a non-``dict``
object is passed as the first argument, a :exc:`TypeError` will be raised.

The ``json_dumps_params`` parameter is a dictionary of keyword arguments
to pass to the ``json.dumps()`` call used to generate the response.

.. versionchanged:: 6.2

In earlier versions, the ``safe`` parameter defaulted to ``True``.

.. deprecated:: 6.2

The ``safe`` parameter is deprecated.

Usage
-----

Expand Down Expand Up @@ -1278,10 +1286,6 @@ using non-dict objects in JSON-encoded responses.
other objects besides dictionaries, as the (now deprecated) ``safe``
parameter defaulted to ``True``, raising :exc:`TypeError`.

.. deprecated:: 6.2

The ``safe`` parameter is deprecated.

Changing the default JSON encoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Loading