Skip to main content

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

AttributeTypeDescription
_appweakref.proxyAn 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

NameTypeDescription
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

NameTypeDescription
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

NameTypeDescription
objt.AnyThe data to serialize.
kwargst.AnyMay be passed to the underlying JSON library.

Returns

TypeDescription
strThe 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

NameTypeDescription
objt.AnyThe data to serialize.
fpt.IO[str]A file opened for writing text. Should use the UTF-8 encoding to be valid JSON.
kwargst.AnyMay be passed to the underlying JSON library.

Returns

TypeDescription
None

loads()

@classmethod
def loads(
s: str | bytes,
kwargs: t.Any
) - > t.Any

Deserialize data as JSON.

Parameters

NameTypeDescription
s`strbytes`
kwargst.AnyMay be passed to the underlying JSON library.

Returns

TypeDescription
t.AnyThe 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

NameTypeDescription
fpt.IO[t.AnyStr]A file opened for reading text or UTF-8 bytes.
kwargst.AnyMay be passed to the underlying JSON library.

Returns

TypeDescription
t.AnyThe 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

NameTypeDescription
argst.AnyA single value to serialize, or multiple values to treat as a list to serialize.
kwargst.AnyTreat as a dict to serialize.

Returns

TypeDescription
[Response](../../wrappers/response.md?sid=src_flask_wrappers_response)A Flask response object containing the serialized JSON data and the correct mimetype.