Home > Mobile >  Why does this json file cause an 'expecting value' error?
Why does this json file cause an 'expecting value' error?

Time:05-19

I'm trying to load a file as JSON.

Here's the data file:

{"Title":"Assignment Checker",
 "Q1_Solution":10517,
 "Q2_Solution":12, 
 "Q3_Solution":52,
 "Q4_Solution":84,
 "Q5_Solution":50,
 "Q6_Solution":1971,
 "Q7_Solution":("Hip", "Flat", "Gambrel", "Mansard", "Shed", "Gable")}

Here's the code that fails:

f = open("checkerData.json")
checkerData = json.load(f)
f.close()

I get this error:

JSONDecodeError: Expecting value: line 8 column 16 (char 166)

CodePudding user response:

Parenthesis are not valid in JSON to represent a list (array).

Fix the JSON to use [ and ] instead.

This is valid:

{
  "Title": "Assignment Checker",
  "Q1_Solution": 10517,
  "Q2_Solution": 12,
  "Q3_Solution": 52,
  "Q4_Solution": 84,
  "Q5_Solution": 50,
  "Q6_Solution": 1971,
  "Q7_Solution": [
    "Hip",
    "Flat",
    "Gambrel",
    "Mansard",
    "Shed",
    "Gable"
  ]
}
  • Related