ds_resource_plugin_py_lib.libs.utils.json_default

File: json_default.py Region: ds_resource_plugin_py_lib/libs/utils

Description

JSON serialization helpers for values that are not natively JSON-encodable.

Example

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

json_default(→ Any)

default callback for json.dumps().

Module Contents

ds_resource_plugin_py_lib.libs.utils.json_default.json_default(value: Any) Any[source]

default callback for 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 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.