{"id":267,"hash":"bb33c279ac4b84d3ce3834177cecaf6d58d6eec6e491b3583e68ca57e75e0987","pattern":"Python - TypeError: Object of type &#39;int64&#39; is not JSON serializable","full_message":"I have a data frame that stores store name and daily sales count. I am trying to insert this to Salesforce using the Python script below.\n\nHowever, I get the following error:\n\nTypeError: Object of type 'int64' is not JSON serializable\n\nBelow, there is the view of the data frame.\n\nStorename,Count\nStore A,10\nStore B,12\nStore C,5\n\nI use the following code to insert it to Salesforce.\n\nupdate_list = []\nfor i in range(len(store)):\n    update_data = {\n        'name': store['entity_name'].iloc[i],\n        'count__c': store['count'].iloc[i] \n    }\n    update_list.append(update_data)\n\nsf_data_cursor = sf_datapull.salesforce_login()\nsf_data_cursor.bulk.Account.update(update_list)\n\nI get the error when the last line above gets executed.\n\nHow do I fix this?","ecosystem":"pypi","package_name":"numpy","package_version":null,"solution":"You can define your own encoder to solve this problem.\n\nimport json\nimport numpy as np\n\nclass NpEncoder(json.JSONEncoder):\n    def default(self, obj):\n        if isinstance(obj, np.integer):\n            return int(obj)\n        if isinstance(obj, np.floating):\n            return float(obj)\n        if isinstance(obj, np.ndarray):\n            return obj.tolist()\n        return super(NpEncoder, self).default(obj)\n\n# Your codes .... \njson.dumps(data, cls=NpEncoder)","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/50916422/python-typeerror-object-of-type-int64-is-not-json-serializable","votes":253,"created_at":"2026-04-19T04:41:42.950180+00:00","updated_at":"2026-04-19T04:51:54.604744+00:00"}