TypeError: Object of type uint32 is not JSON serializable 1

TypeError: Object of type uint32 is not JSON serializable

# It seems like there may be a issue to dump numpy.int64 into json string in Python 3.
# the generic solution: 

def convert(o):
    if isinstance(o, np.generic): return o.item()  
    raise TypeError

json.dumps({'value': numpy.int64(42)}, default=convert)

Here is what the above code is Doing:
1. The json.dumps() function takes an optional argument called default.
2. The default argument is a function that is called whenever the json.dumps() function can’t serialize a value itself.
3. The default function is passed the value that can’t be serialized.
4. The default function should return a serializable value.
5. The default function is called for each value that can’t be serialized.

Similar Posts