Hi @GeethaThatipatri-MSFT sorry for late reply. The solution that you advised did not work. Instead I converted it to a list and later used dataframe through which I could insert it into database.
Below is the steps.
Thanks for your help and follow up. Appreciate it.
Hi @GeethaThatipatri-MSFT Thanks for your reply.
Yes your right! I wanted to store json output into SQL Server 2019 database.
In my case the json file which i need to insert into database is already stored in variable named "data"(screenshot shared previously i.e data = res.read()).
I need to insert that "data" into the database directly where my database name called Rest and table called bms. It is getting connected to database. But i am getting the below error.
Traceback (most recent call last):
File "C:\Users\trees\RESTAPI_Python_Code\Test2.py", line 70, in <module>
cursor.execute(('INSERT INTO dbo.bms([Value],[Unit],[WatchName])'),(json.dumps(data)))
File "C:\Python310\lib\json_init.py", line 231, in dumps
return default_encoder.encode(obj)
File "C:\Python310\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, one_shot=True)
File "C:\Python310\lib\json\encoder.py", line 257, in iterencode
return iterencode(o, 0)
File "C:\Python310\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type bytes is not JSON serializable
Hi @Treesa George Data is of type bytes, can’t run the json.dump() on it as it takes a parameter of type json
Alter json.dumps(data) to json.dumps(data.json()) and give it a try.
Regards
Geetha
Hi, @Treesa George We haven't heard back from you. Just wanted to check if you are still facing the issue?
Regards
Geetha
Sign in to comment