Python Forum
Get Python json data i n SQL Server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Python json data i n SQL Server
#1
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)

'
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 216 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,374 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,089 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  In SQL Server, mix data types. shiv11 0 884 Sep-21-2022, 12:50 PM
Last Post: shiv11
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,228 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Python Split json into separate json based on node value CzarR 1 5,628 Jul-08-2022, 07:55 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 2,840 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 1,897 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 934 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,204 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020