Python TypeError: Object of type int64 is not JSON serializable

Questions

In the process of using JSON. Dumps (param) to convert Python objects to JSON, the following problems appear: typeerror: object of type Int64 is not JSON serializable type

The code is as follows:

param = {
        'remoteId': 'remoteId',
        'fieldCode': 'fieldCode',
        'paramName': 'paramName',
        'operation': 'operation',
        'operationName': 'operationName',
        'paramValue': 0
    }
...
json.dumps(param)

Why

0 in 'paramvalue ': 0 is converted into Int64 object by pandas, which is not recognized by JSON library

Solution

Change the Int64 object into a normal string type. As follows:

'paramValue': str(0)

or

df['paramValue'].apply(str)

Similar Posts: