json() — requests Function Reference
Architecture documentation for the json() function in models.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 49ad2d5b_28fd_baf2_5293_4c3e313ea2e8["json()"] eb32847e_3797_d01a_6e44_345e9ea7e251["Response"] 49ad2d5b_28fd_baf2_5293_4c3e313ea2e8 -->|defined in| eb32847e_3797_d01a_6e44_345e9ea7e251 f73f1552_9580_2f21_8420_b9bd4ba84777["json()"] 49ad2d5b_28fd_baf2_5293_4c3e313ea2e8 -->|calls| f73f1552_9580_2f21_8420_b9bd4ba84777 f3de4c68_3dfd_1ac1_297a_0d79b1ff3031["guess_json_utf()"] 49ad2d5b_28fd_baf2_5293_4c3e313ea2e8 -->|calls| f3de4c68_3dfd_1ac1_297a_0d79b1ff3031 style 49ad2d5b_28fd_baf2_5293_4c3e313ea2e8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/models.py lines 949–982
def json(self, **kwargs):
r"""Decodes the JSON response body (if any) as a Python object.
This may return a dictionary, list, etc. depending on what is in the response.
:param \*\*kwargs: Optional arguments that ``json.loads`` takes.
:raises requests.exceptions.JSONDecodeError: If the response body does not
contain valid json.
"""
if not self.encoding and self.content and len(self.content) > 3:
# No encoding set. JSON RFC 4627 section 3 states we should expect
# UTF-8, -16 or -32. Detect which one to use; If the detection or
# decoding fails, fall back to `self.text` (using charset_normalizer to make
# a best guess).
encoding = guess_json_utf(self.content)
if encoding is not None:
try:
return complexjson.loads(self.content.decode(encoding), **kwargs)
except UnicodeDecodeError:
# Wrong UTF codec detected; usually because it's not UTF-8
# but some other 8-bit codec. This is an RFC violation,
# and the server didn't bother to tell us what codec *was*
# used.
pass
except JSONDecodeError as e:
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
try:
return complexjson.loads(self.text, **kwargs)
except JSONDecodeError as e:
# Catch JSON-related errors and raise as requests.JSONDecodeError
# This aliases json.JSONDecodeError and simplejson.JSONDecodeError
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does json() do?
json() is a function in the requests codebase, defined in src/requests/models.py.
Where is json() defined?
json() is defined in src/requests/models.py at line 949.
What does json() call?
json() calls 2 function(s): guess_json_utf, json.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free