0

When you try to open a json file, this error comes out

    Traceback (most recent call last):
  File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 227, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\vlad0\Desktop\bot\bot.py", line 577, in on_message
    info = json.load(open('servers/'+str(server)+'/reports/'+str(user["MaxRepID"])+'/info.json'))
  File "C:\py36\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\py36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\py36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\py36\lib\json\decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 18 (char 19)

Here is the code that opens it (The path is correct)

info = json.load(open('servers/'+str(server)+'/reports/'+str(user["MaxRepID"])+'/info.json'))

json file

{
  "Channel": "", /* ID */
  "Created": "", /* Date */
  "Author": "", /* who created */
  "Is_closed": "False",
  "Is_open": "False",
  "Is_deleted": "False"
}

As you can see, double brackets are not skipped, but what is the error?

1 Answers1

0

I don't think C-style comments are allowed in a JSON file (at least the Python JSON parser doesn't allow them), so try removing them.

Edit: As suggested by @Marcus in the comments, this question has some options for parsing a JSON file that has comments, including using packages such as jsmin, jstyleson, and jsoncomment, which are all on PyPI and installable via pip.

Matt Pitkin
  • 3,989
  • 1
  • 18
  • 32