Method: flask.json.dumps
Calls: 514, Exceptions: 0, Paths: 2Back
Path 1: 496 calls (0.96)
{} (452) {'testing': 42} (7) dict (7) {'_permanent': True, 'foo': 3} (3) {'test': 'test'} (3) {'value': '42'} (2) {'foo': 42} (2) {'foo': 1, '_permane...
dict (495) {} (1)
'{}' (452) '{"testing":42}' (7) '{"_flashes":[{" t":["message","Hello World"]},{" t":["error","Hello World"]},{" t":["warning",{" m":"Testing...
1def dumps(obj: t.Any, **kwargs: t.Any) -> str:
2 """Serialize data as JSON.
3
4 If :data:`~flask.current_app` is available, it will use its
5 :meth:`app.json.dumps() <flask.json.provider.JSONProvider.dumps>`
6 method, otherwise it will use :func:`json.dumps`.
7
8 :param obj: The data to serialize.
9 :param kwargs: Arguments passed to the ``dumps`` implementation.
10
11 .. versionchanged:: 2.3
12 The ``app`` parameter was removed.
13
14 .. versionchanged:: 2.2
15 Calls ``current_app.json.dumps``, allowing an app to override
16 the behavior.
17
18 .. versionchanged:: 2.0.2
19 :class:`decimal.Decimal` is supported by converting to a string.
20
21 .. versionchanged:: 2.0
22 ``encoding`` will be removed in Flask 2.1.
23
24 .. versionchanged:: 1.0.3
25 ``app`` can be passed directly, rather than requiring an app
26 context for configuration.
27 """
28 if current_app:
29 return current_app.json.dumps(obj, **kwargs)
30
31 kwargs.setdefault("default", _default)
32 return _json.dumps(obj, **kwargs)
Path 2: 18 calls (0.04)
dict (6) datetime (3) Decimal (1) {'a': 1, 'b': 2} (1) test_html_method.
dict (11) {} (7)
'"Sun, 01 Jan 2017 12:34:56 GMT"' (1) '"Sun, 01 Jan 2017 20:34:56 GMT"' (1) '"Sun, 01 Jan 2017 03:34:56 GMT"' (1) '"0.003"' (1) '{"a": 1, "b": 2}' (1)...
1def dumps(obj: t.Any, **kwargs: t.Any) -> str:
2 """Serialize data as JSON.
3
4 If :data:`~flask.current_app` is available, it will use its
5 :meth:`app.json.dumps() <flask.json.provider.JSONProvider.dumps>`
6 method, otherwise it will use :func:`json.dumps`.
7
8 :param obj: The data to serialize.
9 :param kwargs: Arguments passed to the ``dumps`` implementation.
10
11 .. versionchanged:: 2.3
12 The ``app`` parameter was removed.
13
14 .. versionchanged:: 2.2
15 Calls ``current_app.json.dumps``, allowing an app to override
16 the behavior.
17
18 .. versionchanged:: 2.0.2
19 :class:`decimal.Decimal` is supported by converting to a string.
20
21 .. versionchanged:: 2.0
22 ``encoding`` will be removed in Flask 2.1.
23
24 .. versionchanged:: 1.0.3
25 ``app`` can be passed directly, rather than requiring an app
26 context for configuration.
27 """
28 if current_app:
29 return current_app.json.dumps(obj, **kwargs)
30
31 kwargs.setdefault("default", _default)
32 return _json.dumps(obj, **kwargs)