skneuromsi.utils.custom_json module
Custom JSON encoding and decoding module.
This module provides custom JSON encoding and decoding functionality by extending the default JSONEncoder and providing additional converter functions for various data types that are not supported by the default encoder.
- class skneuromsi.utils.custom_json.CustomJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoderCustom JSON encoder class that extends the default JSONEncoder.
This class provides additional functionality for encoding various data types that are not supported by the default JSONEncoder, such as tuples, sets, frozensets, datetime objects, NumPy types, and NumPy arrays.
- CONVERTERS = ((<class 'tuple'>, <class 'list'>), (<class 'set'>, <class 'list'>), (<class 'frozenset'>, <class 'list'>), (<class 'datetime.datetime'>, <method 'isoformat' of 'datetime.datetime' objects>), (<class 'numpy.integer'>, <class 'int'>), (<class 'numpy.floating'>, <class 'float'>), (<class 'numpy.complexfloating'>, <class 'complex'>), (<class 'numpy.bool'>, <class 'bool'>), (<class 'numpy.ndarray'>, <method 'tolist' of 'numpy.ndarray' objects>))
A dictionary mapping data types to their corresponding converter functions. The converter functions are used to convert the data types to JSON-serializable representations.
- skneuromsi.utils.custom_json.dump(obj, fp, **kwargs)[source]
Serialize obj as a JSON formatted stream to fp (.write()-supporting file-like object).
- Parameters:
obj (object) – The object to be serialized.
fp (file-like object) – A .write()-supporting file-like object to write the JSON formatted stream to.
**kwargs – Additional keyword arguments to be passed to the underlying json.dump() function.
- Return type:
None
- skneuromsi.utils.custom_json.dumps(obj, **kwargs)[source]
Serialize obj to a JSON formatted str.
- Parameters:
obj (object) – The object to be serialized.
**kwargs – Additional keyword arguments to be passed to the underlying json.dumps() function.
- Returns:
The JSON formatted string representation of the object.
- Return type:
str
- skneuromsi.utils.custom_json.load(fp, **kwargs)[source]
Deserialize fp (.read()-supporting file-like object containing a JSON document) to a Python object.
- Parameters:
fp (file-like object) – A .read()-supporting file-like object containing a JSON document.
**kwargs – Additional keyword arguments to be passed to the underlying json.load() function.
- Returns:
The Python object deserialized from the JSON document.
- Return type:
object
- skneuromsi.utils.custom_json.loads(text, **kwargs)[source]
Deserialize text (str, bytes or bytearray instance containing a JSON document) to a Python object.
- Parameters:
text (str, bytes or bytearray) – A string, bytes or bytearray instance containing a JSON document.
**kwargs – Additional keyword arguments to be passed to the underlying json.loads() function.
- Returns:
The Python object deserialized from the JSON document.
- Return type:
object