I'm here trying to parse JSON string that comes from a sql table, but while parsing it is giving the error TypeError: string indices must be integers
at line result = json_normalize(json_st,'results')
here is the code snippet
from pandas.io.json import json_normalize
import pyodbc
cnxn = pyodbc.connect('connection string')
cursor = cnxn.cursor()
cursor.execute("select TOP 1 GEOCODE_ID, JSON from GEOCODE_TBL where GEOCODE_ID = 20")
ID=[]
JSON=[]
for row in cursor.fetchall():
ID.append(row[0])
JSON.append(row[1])
json_st1 = json.dumps(JSON)
json_st=json.loads(json_st1)
result = json_normalize(json_st,'results')
Any suggestion on this will be helpful.
Thanks
Domnick.
row[0
] androw[1]
and see what they are , you can use enumerate and use index no there.type(row[1]) Out[119]: str