Returns the JSON encoded content of the response, if any. `**kwargs` are optional arguments that will be passed to `json.loads()`. Will raise if the content can not be decoded and then parsed as JSON. *Raises:* - `json.decoder.JSONDecodeError` if c
(self, **kwargs: Any)
| 494 | raise ValueError(f"Invalid content encoding {encoding!r}") |
| 495 | |
| 496 | def json(self, **kwargs: Any) -> Any: |
| 497 | """ |
| 498 | Returns the JSON encoded content of the response, if any. |
| 499 | `**kwargs` are optional arguments that will be |
| 500 | passed to `json.loads()`. |
| 501 | |
| 502 | Will raise if the content can not be decoded and then parsed as JSON. |
| 503 | |
| 504 | *Raises:* |
| 505 | - `json.decoder.JSONDecodeError` if content is not valid JSON. |
| 506 | - `TypeError` if the content is not available, for example because the response |
| 507 | has been streamed. |
| 508 | """ |
| 509 | content = self.get_content(strict=False) |
| 510 | if content is None: |
| 511 | raise TypeError("Message content is not available.") |
| 512 | else: |
| 513 | return json.loads(content, **kwargs) |
| 514 | |
| 515 | |
| 516 | class Request(Message): |