Python Forum
Get Python json data i n SQL Server - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Get Python json data i n SQL Server (/thread-26726.html)



Get Python json data i n SQL Server - Djin - May-11-2020

Greetings,

I am very new to Python and am looking for help to get a json document inserted into SQL so I can parse it. This will be an ongoing process that I'm hoping to do with SSIS. I've managed to get the content I want (from Survey Monkey API) using the following code. This is run within SQL Server SSMS and puts the data I want in the Surveys_Json variable. I need to get this outputted to an SQL Server database. I know SQL much more than I know Python. Once I get the document into SQL, I can parse it using the Json functions there. Any help would be appreciated.

EXECUTE sp_execute_external_script

@language = N'Python'

, @Script = N'

import requests

import json

client = requests.session()

headers = {

"Authorization": "bearer %s" % "apikey",

"Content-Type": "application/json"

}

data = {}

HOST = "https://api.surveymonkey.net"

SURVEY_LIST_ENDPOINT = "/v3/surveys/"

uri = "%s%s" % (HOST, SURVEY_LIST_ENDPOINT)

surveylist = client.get(uri, headers=headers)

surveys_json = surveylist.json()

print(surveys_json)

'


RE: Get Python json data i n SQL Server - ndc85430 - May-13-2020

It sounds like what you're asking is basically "how do I interact with an SQL Server database from a Python script?". If so, you'll need a third party library to do that; see this for details.