Question

I'm trying to open a file to view the data in test.json file. File contains string data.

Here is my code:

import json
from pprint import pprint
    with open("D:\python\abc.json") as json_file:
     json_data = json.load(json_file)
        pprint(json_data)

Here is the error generating, I'm confused as I'm newbie in Python. Help Required.

    Traceback (most recent call last):
  File "C:\Users\joh\workspace\newdic\dic.py", line 20, in <module>
    json_data = json.load(json_file)
  File "C:\Python33\lib\json\__init__.py", line 271, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Python33\lib\json\__init__.py", line 316, in loads
    return _default_decoder.decode(s)
  File "C:\Python33\lib\json\decoder.py", line 351, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python33\lib\json\decoder.py", line 367, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 21 column 9 (char 387)
Was it helpful?

Solution

The error is clear. ValueError: Expecting ',' delimiter: line 21 column 9 (char 387)

Make sure that the Json file is valid.

Use http://jsonlint.com/ to validate your Json. Just copy and paste and it will tell you if it is not valid. Once it is this library should read it. You can post your Json and we can look at it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top