Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONDecodeError: Expecting ',' delimiter: line 1 column 43 (char 42)

Tags:

python

I have read on many examples here already on SO. Unfortunately, I keep getting this error,

Error:

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 43 (char 42)

json file:

{"people": [{"name": "Scott", "from": "Nebraska", "website": "stackabuse.com"}, {"name": "Larry", "from": "Michigan", "website": "google.com"}, {"name": "Tim", "from": "Alabama", "website": "apple.com"}]}

And another separate json file:

{"scores":[{"name":"Larry","result":["0":"24","1":"43","2":"56"]},{"name":"Tim","result":["0":"44","1":"29","2":"34"]}]}

python code:

with open('data.json') as file:
          data = json.load(file)

    print(data)
like image 321
John Smith Avatar asked Dec 21 '16 11:12

John Smith


1 Answers

Your JSON is invalid, it has : tokens in an array:

"result": ["0": "24", "1": "43", "2": "56"]
#             ^          ^          ^

and

"result": ["0": "44", "1": "29", "2": "34"]
#             ^          ^          ^

Fix your JSON input; either replace those colons with commas, remove the "0":, "1":, and "2": 'indices', or replace the [...] array brackets with {...} JSON object braces.

like image 87
Martijn Pieters Avatar answered Oct 23 '22 21:10

Martijn Pieters