TypeError: Object of type bool_ is not JSON serializable

It’s likely because of this issue (or something similar):

import numpy as np
import json

json.dumps({"X": np.int32(5) > 5})

TypeError: Object of type ‘bool_’ is not JSON serializable

The issue is that you end up with something of type bool_ instead of bool.

Calling bool()on whichever value(s) are of the wrong type will fix your issue (assuming your version of bool_ behaves similarly to numpy’s):

json.dumps({"X": bool(np.int32(5) > 5)})

‘{“X”: false}’

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)