ds_resource_plugin_py_lib.libs.utils.json_default ================================================= .. py:module:: ds_resource_plugin_py_lib.libs.utils.json_default .. autoapi-nested-parse:: **File:** ``json_default.py`` **Region:** ``ds_resource_plugin_py_lib/libs/utils`` Description ----------- JSON serialization helpers for values that are not natively JSON-encodable. .. rubric:: Example .. code-block:: python from datetime import datetime import json from ds_resource_plugin_py_lib.libs.utils.json_default import json_default payload = json.dumps({"created_at": datetime(2024, 3, 15, 10, 30)}, default=json_default) Functions --------- .. autoapisummary:: ds_resource_plugin_py_lib.libs.utils.json_default.json_default Module Contents --------------- .. py:function:: json_default(value: Any) -> Any ``default`` callback for :func:`json.dumps`. Maps common Python types (for example ``datetime``) to JSON-serializable values. Scalar-like objects with a callable ``.item()`` (for example numpy scalars) are unwrapped before encoding. Unknown types raise :class:`TypeError`, matching stdlib behavior. ``bytes`` and ``bytearray`` are intentionally not converted: JSON has no binary type, and decoding bytes as text would silently change the data.