I am working on building a test software as a side project. I have been given questions for the test in a JSON format. I intend to parse the JSON and store it into an SQL table with the following schema:-
TABLE NAME - QUESTIONS
QUESTION_NO - INT (PRIMARY KEY) - AUTO_INCREMENT,
QUESTION_DESC - VARCHAR(255),
OPTA - VARCHAR(255),
OPTB - VARCHAR(255),
OPTC - VARCHAR(255),
OPTD - VARCHAR(255),
CORRECTOPT - VARCHAR(1) [Should be 'A','B','C','D']
The JSON is in the following format:-
[
{
"1": "Total number of ATP produced during Kreb's cycle",
"2": "what is referred to as reference carbohydrate?"
},
{
"1": {
"a": "8",
"b": "11",
"c": "12",
"d": "36"
},
"2": {
"a": "glucose",
"b": "glyceraldehde",
"c": "fructose",
"d": "lactose"
}
},
{
"1": "12",
"2": "glyceraldehyde"
}
]
I initially tried writing a Python code to parse the JSON which is as follows:-
import json
with open('BIOset1.json') as f:
data = json.load(f)
print(data)
Here BIOset1.json is the name of the JSON file I am trying to parse. But, I get the following error:-
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Can someone please help me to parse this JSON file and retrieve the data in the following format so that I can insert the data into the SQL table?
I come from a non-programming background and I am trying to bring out a genuine change in my university through these questions.
Any help would be much appreciated.
[{
"QUESTION_DESC": "Total number of ATP produced during Kreb's cycle",
"OPTA": "8",
"OPTB": "11",
"OPTC": "12",
"OPTD": "36",
"CORRECTOPT": "C"
},
{
"QUESTION_DESC": "what is referred to as reference carbohydrate?",
"OPTA": "glucose",
"OPTB": "fructose",
"OPTC": "lactose",
"OPTD": "aldehyde",
"CORRECTOPT": "B"
}
]