close

[Solved] Python error : TypeError: Object of type ‘Timestamp’ is not JSON serializable’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python error : TypeError: Object of type ‘Timestamp’ 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 error : TypeError: Object of type ‘Timestamp’ is not JSON serializable’ Error Occurs?

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

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

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

    To Solve Python error : TypeError: Object of type 'Timestamp' is not JSON serializable' Error If you get an error TimeStamp has no attribute as "astype(str)", you can try, for example, str(timeseries.index[0]). This will convert the timestamp into a string that can then be serialized.

  2. Python error : TypeError: Object of type 'Timestamp' is not JSON serializable'

    To Solve Python error : TypeError: Object of type 'Timestamp' is not JSON serializable' Error If you get an error TimeStamp has no attribute as "astype(str)", you can try, for example, str(timeseries.index[0]). This will convert the timestamp into a string that can then be serialized.

Solution 1

You can try convert datetime to string:

df['Date'] = df['Date'].astype(str)

Or:

df['Date'] = df['Date'].dt.strftime('%Y-%m-%d %H:%M:%S')

print (df.dtypes)
Id      object
Name    object
Date    object
Type    object
dtype: object

Solution 2

If you get an error TimeStamp has no attribute as "astype(str)", you can try, for example, str(timeseries.index[0]). This will convert the timestamp into a string that can then be serialized.

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