[Solved]: TypeError: Object of type 'float32' is not JSON serializable

Method 1:

Create your own JSON encoder.

import jsonclass MyEncoder(json.JSONEncoder):    def default(self, obj):        if isinstance(obj, numpy.integer):            return int(obj)        elif isinstance(obj, numpy.floating):            return float(obj)        elif isinstance(obj, numpy.ndarray):            return obj.tolist()        else:            return super(MyEncoder, self).default(obj)return json.dumps(data, cls=MyEncoder)

Method 2:

The best solution if you have nested numpy arrays in a dictionary:

import jsonimport numpy as npclass NumpyEncoder(json.JSONEncoder):    """ Special json encoder for numpy types """    def default(self, obj):        if isinstance(obj, (np.int_, np.intc, np.intp, np.int8,            np.int16, np.int32, np.int64, np.uint8,            np.uint16, np.uint32, np.uint64)):            return int(obj)        elif isinstance(obj, (np.float_, np.float16, np.float32,             np.float64)):            return float(obj)        elif isinstance(obj,(np.ndarray,)): #### This is the fix            return obj.tolist()        return json.JSONEncoder.default(self, obj)dumped = json.dumps(data, cls=NumpyEncoder)with open(path, 'w') as f:    json.dump(dumped, f)

Method 3:

You can use Pandas:

import pandas as pdpd.Series(your_array).to_json(orient='values')