MCPcopy
hub / github.com/pallets/flask / dumps

Function dumps

src/flask/json/__init__.py:13–44  ·  view source on GitHub ↗

Serialize data as JSON. If :data:`~flask.current_app` is available, it will use its :meth:`app.json.dumps() <flask.json.provider.JSONProvider.dumps>` method, otherwise it will use :func:`json.dumps`. :param obj: The data to serialize. :param kwargs: Arguments passed to the ``du

(obj: t.Any, **kwargs: t.Any)

Source from the content-addressed store, hash-verified

11
12
13def dumps(obj: t.Any, **kwargs: t.Any) -> str:
14 """Serialize data as JSON.
15
16 If :data:`~flask.current_app` is available, it will use its
17 :meth:`app.json.dumps() <flask.json.provider.JSONProvider.dumps>`
18 method, otherwise it will use :func:`json.dumps`.
19
20 :param obj: The data to serialize.
21 :param kwargs: Arguments passed to the ``dumps`` implementation.
22
23 .. versionchanged:: 2.3
24 The ``app`` parameter was removed.
25
26 .. versionchanged:: 2.2
27 Calls ``current_app.json.dumps``, allowing an app to override
28 the behavior.
29
30 .. versionchanged:: 2.0.2
31 :class:`decimal.Decimal` is supported by converting to a string.
32
33 .. versionchanged:: 2.0
34 ``encoding`` will be removed in Flask 2.1.
35
36 .. versionchanged:: 1.0.3
37 ``app`` can be passed directly, rather than requiring an app
38 context for configuration.
39 """
40 if current_app:
41 return current_app.json.dumps(obj, **kwargs)
42
43 kwargs.setdefault("default", _default)
44 return _json.dumps(obj, **kwargs)
45
46
47def dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None:

Callers 1

dumpsMethod · 0.85

Calls 2

setdefaultMethod · 0.80
dumpsMethod · 0.45

Tested by

no test coverage detected