Method: flask.json.dump
Calls: 1, Exceptions: 0, Paths: 1Back
Path 1: 1 calls (1.0)
{'name': 'Flask'} (1)
StringIO (1)
{} (1)
1def dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None:
2 """Serialize data as JSON and write to a file.
3
4 If :data:`~flask.current_app` is available, it will use its
5 :meth:`app.json.dump() <flask.json.provider.JSONProvider.dump>`
6 method, otherwise it will use :func:`json.dump`.
7
8 :param obj: The data to serialize.
9 :param fp: A file opened for writing text. Should use the UTF-8
10 encoding to be valid JSON.
11 :param kwargs: Arguments passed to the ``dump`` implementation.
12
13 .. versionchanged:: 2.3
14 The ``app`` parameter was removed.
15
16 .. versionchanged:: 2.2
17 Calls ``current_app.json.dump``, allowing an app to override
18 the behavior.
19
20 .. versionchanged:: 2.0
21 Writing to a binary file, and the ``encoding`` argument, will be
22 removed in Flask 2.1.
23 """
24 if current_app:
25 current_app.json.dump(obj, fp, **kwargs)
26 else:
27 kwargs.setdefault("default", _default)
28 _json.dump(obj, fp, **kwargs)