close

[Solved] Python – TypeError: Object of type ‘int64’ is not JSON serializable

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python – TypeError: Object of type ‘int64’ is not JSON serializable in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python – TypeError: Object of type ‘int64’ is not JSON serializable Error Occurs?

Today I get the following error Python – TypeError: Object of type ‘int64’ is not JSON serializable in python.

How To Solve Python – TypeError: Object of type ‘int64’ is not JSON serializable Error ?

  1. How To Solve Python – TypeError: Object of type 'int64' is not JSON serializable Error ?

    To Solve Python – TypeError: Object of type 'int64' is not JSON serializable Error json does not recognize NumPy data types. Convert the number to a Python int before serializing the object:

  2. Python – TypeError: Object of type 'int64' is not JSON serializable

    To Solve Python – TypeError: Object of type 'int64' is not JSON serializable Error json does not recognize NumPy data types. Convert the number to a Python int before serializing the object:

Solution 1

json does not recognize NumPy data types. Convert the number to a Python int before serializing the object:

'count__c': int(store['count'].iloc[i])

Solution 2

You can define your own encoder to solve this problem.

import json
import numpy as np

class NpEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        if isinstance(obj, np.floating):
            return float(obj)
        if isinstance(obj, np.ndarray):
            return obj.tolist()
        return super(NpEncoder, self).default(obj)

# Your codes .... 
json.dumps(data, cls=NpEncoder)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read