extended_data.primitives.formats.json¶
JSON Utilities Module.
This module provides utilities for encoding and decoding JSON.
Module Contents¶
Functions¶
Decodes a JSON string or bytes into a Python object using orjson. |
|
Encodes a Python object into a JSON string using orjson. |
API¶
- extended_data.primitives.formats.json.decode_json(json_data: str | memoryview | bytes | bytearray) Any¶
Decodes a JSON string or bytes into a Python object using orjson.
Args: json_data (str | memoryview | bytes | bytearray): The JSON string or bytes to decode.
Returns: Any: The decoded Python object.
- extended_data.primitives.formats.json.encode_json(raw_data: Any, default: collections.abc.Callable[[Any], Any] | None = None, indent_2: bool = False, naive_utc: bool = False, non_str_keys: bool = False, omit_microseconds: bool = False, passthrough_dataclass: bool = False, passthrough_datetime: bool = False, passthrough_subclass: bool = False, serialize_numpy: bool = False, strict_integer: bool = False, utc_z: bool = False, sort_keys: bool = False, append_newline: bool = False) str¶
Encodes a Python object into a JSON string using orjson.
Args: raw_data (Any): The Python object to encode. default (Callable[[Any], Any] | None): A callable for serializing unsupported types. indent_2 (bool): Pretty-print output with an indent of two spaces. naive_utc (bool): Serialize naive datetime objects as UTC. non_str_keys (bool): Allow dict keys of types other than str. omit_microseconds (bool): Omit microseconds in datetime and time objects. passthrough_dataclass (bool): Passthrough dataclasses to default handler. passthrough_datetime (bool): Passthrough datetime objects to default handler. passthrough_subclass (bool): Passthrough subclasses of built-in types to default handler. serialize_numpy (bool): Serialize numpy arrays natively. strict_integer (bool): Enforce 53-bit limit on integers. utc_z (bool): Use ‘Z’ instead of ‘+00:00’ for UTC datetime. sort_keys (bool): Serialize dict keys in sorted order. append_newline (bool): Append newline to the end of the output.
Returns: str: The encoded JSON string.
Raises: orjson.JSONEncodeError: If an unsupported type is encountered and default is not provided.