class documentation

A standard set of JSON operations for an application. Subclasses of this can be used to customize JSON behavior or use different JSON libraries. To implement a provider for a specific library, subclass this base class and implement at least :meth:`dumps` and :meth:`loads`. All other methods have default implementations. To use a different provider, either subclass ``Flask`` and set :attr:`~flask.Flask.json_provider_class` to a provider class, or set :attr:`app.json <flask.Flask.json>` to an instance of the class. :param app: An application instance. This will be stored as a :class:`weakref.proxy` on the :attr:`_app` attribute. .. versionadded:: 2.2

Method __init__ Undocumented
Method dump Serialize data as JSON and write to a file.
Method dumps Serialize data as JSON.
Method load Deserialize data as JSON read from a file.
Method loads Deserialize data as JSON.
Method response Serialize the given arguments as JSON, and return a :class:`~flask.Response` object with the ``application/json`` mimetype.
Method _prepare_response_obj Undocumented
Instance Variable _app Undocumented
def __init__(self, app: Flask): (source)

Undocumented

def dump(self, obj: t.Any, fp: t.IO[str], **kwargs: t.Any): (source)

Serialize data as JSON and write to a file. :param obj: The data to serialize. :param fp: A file opened for writing text. Should use the UTF-8 encoding to be valid JSON. :param kwargs: May be passed to the underlying JSON library.

def dumps(self, obj: t.Any, **kwargs: t.Any) -> str: (source)

Serialize data as JSON. :param obj: The data to serialize. :param kwargs: May be passed to the underlying JSON library.

def load(self, fp: t.IO[t.AnyStr], **kwargs: t.Any) -> t.Any: (source)

Deserialize data as JSON read from a file. :param fp: A file opened for reading text or UTF-8 bytes. :param kwargs: May be passed to the underlying JSON library.

def loads(self, s: str|bytes, **kwargs: t.Any) -> t.Any: (source)

Deserialize data as JSON. :param s: Text or UTF-8 bytes. :param kwargs: May be passed to the underlying JSON library.

def response(self, *args: t.Any, **kwargs: t.Any) -> Response: (source)

Serialize the given arguments as JSON, and return a :class:`~flask.Response` object with the ``application/json`` mimetype. The :func:`~flask.json.jsonify` function calls this method for the current application. Either positional or keyword arguments can be given, not both. If no arguments are given, ``None`` is serialized. :param args: A single value to serialize, or multiple values to treat as a list to serialize. :param kwargs: Treat as a dict to serialize.

def _prepare_response_obj(self, args: t.Tuple[t.Any, ...], kwargs: t.Dict[str, t.Any]) -> t.Any: (source)

Undocumented

Undocumented