JSONProvider
A standard set of JSON operations for an application. Subclasses of this can be used to customize JSON behavior or use different JSON libraries.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _app | weakref.proxy | An application instance stored as a weakref.proxy to provide access to application configuration and state without creating circular references. |
Constructor
Signature
def JSONProvider(
app: [App](../../sansio/app/app.md?sid=src_flask_sansio_app_app)
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| app | [App](../../sansio/app/app.md?sid=src_flask_sansio_app_app) | An application instance to be stored as a weakref.proxy. |
Signature
def JSONProvider(
app: [App](../../sansio/app/app.md?sid=src_flask_sansio_app_app)
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| app | [App](../../sansio/app/app.md?sid=src_flask_sansio_app_app) | The Flask application instance to be stored as a weak reference. |
Methods
dumps()
@classmethod
def dumps(
obj: t.Any,
kwargs: t.Any
) - > str
Serialize data as JSON.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | t.Any | The data to serialize. |
| kwargs | t.Any | May be passed to the underlying JSON library. |
Returns
| Type | Description |
|---|---|
str | The JSON-formatted string representation of the object. |
dump()
@classmethod
def dump(
obj: t.Any,
fp: t.IO[str],
kwargs: t.Any
) - > None
Serialize data as JSON and write to a file.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | t.Any | The data to serialize. |
| fp | t.IO[str] | A file opened for writing text. Should use the UTF-8 encoding to be valid JSON. |
| kwargs | t.Any | May be passed to the underlying JSON library. |
Returns
| Type | Description |
|---|---|
None |
loads()
@classmethod
def loads(
s: str | bytes,
kwargs: t.Any
) - > t.Any
Deserialize data as JSON.
Parameters
| Name | Type | Description |
|---|---|---|
| s | `str | bytes` |
| kwargs | t.Any | May be passed to the underlying JSON library. |
Returns
| Type | Description |
|---|---|
t.Any | The Python object representation of the JSON data. |
load()
@classmethod
def load(
fp: t.IO[t.AnyStr],
kwargs: t.Any
) - > t.Any
Deserialize data as JSON read from a file.
Parameters
| Name | Type | Description |
|---|---|---|
| fp | t.IO[t.AnyStr] | A file opened for reading text or UTF-8 bytes. |
| kwargs | t.Any | May be passed to the underlying JSON library. |
Returns
| Type | Description |
|---|---|
t.Any | The Python object representation of the JSON data read from the file. |
response()
@classmethod
def response(
args: t.Any,
kwargs: t.Any
) - > [Response](../../wrappers/response.md?sid=src_flask_wrappers_response)
Serialize the given arguments as JSON, and return a :class:~flask.Response object with the application/json mimetype.
Parameters
| Name | Type | Description |
|---|---|---|
| args | t.Any | A single value to serialize, or multiple values to treat as a list to serialize. |
| kwargs | t.Any | Treat as a dict to serialize. |
Returns
| Type | Description |
|---|---|
[Response](../../wrappers/response.md?sid=src_flask_wrappers_response) | A Flask response object containing the serialized JSON data and the correct mimetype. |