Reputation: 51
I'm new with python and I ran the code below and got this error message. I saw from another similar post that I have two json files? But I don't really understand since I only load one into my jupyter notebook. I tried deleting the json file and reupload it to jupyter notebook but it doesn't work.
How would I be able to fix this? Thank you.
import json
with open('file.json') as f:
json = json.load(f)
print(json)
I received this message:
JSONDecodeError Traceback (most recent call last)
<ipython-input-3-5b475df8ffe8> in <module>
2
3 with open('file.json') as f:
----> 4 json = json.load(f)
5
6 print(json)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
291 kwarg; otherwise ``JSONDecoder`` is used.
292 """
--> 293 return loads(fp.read(),
294 cls=cls, object_hook=object_hook,
295 parse_float=parse_float, parse_int=parse_int,
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
348 cls = JSONDecoder
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py in decode(self, s, _w)
338 end = _w(s, end).end()
339 if end != len(s):
--> 340 raise JSONDecodeError("Extra data", s, end)
341 return obj
342
JSONDecodeError: Extra data: line 2 column 1 (char 2702)
Upvotes: 1
Views: 856
Reputation:
About the error, you should first check whether it is an error in your json file. Consider showing your json file data out here. And according to the error has thrown out, Line 2 has some mistakes
Upvotes: 1