4.8. Json Encoder

class asari.json_encoder.NpEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

To handle numpy data types in JSON, using Jie Young’s solution at StackOverflow: https://stackoverflow.com/questions/50916422/python-typeerror-object-of-type-int64-is-not-json-serializable

default(obj)[source]

This function converts obj into something that can be serialized by JSON, largely for handling numpy datatypes that, despite being largely equivalent to their pure python equivalents, cannot be serialized.

Parameters:

obj (np.integer or np.floating or np.ndarray or other serializable object instance) – for the numpy objects above, they are cast to their python ‘equivalents’, i.e., np.integer -> int, np.floating -> float, np.ndarray -> list, else, the object is converted to its default serialization representation.