Here is a subset of my json file:
d = {'data': {'questions': [{'id': 6574,
'text': 'Question #1',
'instructionalText': '',
'minimumResponses': 0,
'maximumResponses': None,
'sortOrder': 1,
'answers': [{'id': 362949, 'text': 'Answer #1', 'parentId': None},
{'id': 362950, 'text': 'Answer #2', 'parentId': None},
{'id': 362951, 'text': 'Answer #3', 'parentId': None},
{'id': 362952, 'text': 'Answer #4', 'parentId': None}]}]}}
I want to place this into a dataframe with each question and a row for each answer.
Python code:
from pandas import json_normalize
import json
fields = ['text','answers.text']
with open(R'response.json') as f:
d = json.load(f)
data = json_normalize(d['data'],['questions'],errors='ignore')
data = data[fields]
print(data)
Which produces a KeyError:
KeyError: "['answers.text'] not in index"
Been at this for a few hours and absolutely cannot figure this out. I feel like it should be quite simple, but it never is.