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)
| 11 | |
| 12 | |
| 13 | def 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 | |
| 47 | def dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None: |
no test coverage detected