The Processing Method for 'xxx is not json serializable' in Python JSON is jsonserializable.
1 predictions = self.model.predict(x_data, verbose=0)[0] 2 y_pred_idx = np.argmax(predictions)3 y_pred_prob = predictions[y_pred_idx]4 y_pred_label = self.le.inverse_transform(y_pred_idx) 5 res = OrderedDict()6 res['first'] = self.first_label2name[y_pred_label[0]]7 res['second'] = self.second_label2name[y_pred_label]8 res['probability'] = y_pred_prob9 out.write(json.dumps(res, ensure_ascii=False) + '\n')
Error: '0. 80454153 is not JSON serializable'
Type of the output y_pred_prob: <type 'numpy. float32'>
Refer to Region:
Ultimately, it looks likejson
Is telling you thatint
Isn't serializable, but really, it's telling you that this particle np. int32 (or whatever type you actually have) isn't serializable. (No real surprise there -- No np. int32IsSerializable ).
Json Cannot serialize np. int32, np. float32, or other types. It can be solved through custom serializer or direct type conversion.
Therefore, you can explicitly convert data to the float type in Row 3: res ['bability '] = float (y_pred_prob ).