MCPcopy
hub / github.com/django/django / JsonResponse

Class JsonResponse

django/http/response.py:737–768  ·  view source on GitHub ↗

An HTTP response class that consumes data to be serialized to JSON. :param data: Data to be dumped into json. By default only ``dict`` objects are allowed to be passed due to a security flaw before ECMAScript 5. See the ``safe`` parameter for more information. :param encode

Source from the content-addressed store, hash-verified

735
736
737class JsonResponse(HttpResponse):
738 """
739 An HTTP response class that consumes data to be serialized to JSON.
740
741 :param data: Data to be dumped into json. By default only ``dict`` objects
742 are allowed to be passed due to a security flaw before ECMAScript 5. See
743 the ``safe`` parameter for more information.
744 :param encoder: Should be a json encoder class. Defaults to
745 ``django.core.serializers.json.DjangoJSONEncoder``.
746 :param safe: Controls if only ``dict`` objects may be serialized. Defaults
747 to ``True``.
748 :param json_dumps_params: A dictionary of kwargs passed to json.dumps().
749 """
750
751 def __init__(
752 self,
753 data,
754 encoder=DjangoJSONEncoder,
755 safe=True,
756 json_dumps_params=None,
757 **kwargs,
758 ):
759 if safe and not isinstance(data, dict):
760 raise TypeError(
761 "In order to allow non-dict objects to be serialized set the "
762 "safe parameter to False."
763 )
764 if json_dumps_params is None:
765 json_dumps_params = {}
766 kwargs.setdefault("content_type", "application/json")
767 data = json.dumps(data, cls=encoder, **json_dumps_params)
768 super().__init__(content=data, **kwargs)

Callers 15

getMethod · 0.90
render_to_responseMethod · 0.90
return_json_responseFunction · 0.90
extra_jsonMethod · 0.90
file_upload_echoFunction · 0.90
file_upload_echo_contentFunction · 0.90
json_response_viewFunction · 0.90

Calls

no outgoing calls