-2

The json module is not loading the json file. I have provided the correct path of the json file and i am just loading the file and trying to print it however it just is showing this error and i am not able to find a way around.

import json
f = open('test.json', 'r')
json.load(f)
f.close()

The error output is :

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/helloworld/Data_project/Sort_user.py", line 10, in <module>
    json.load(f)
  File "C:\Program Files\Python37\lib\json\__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Program Files\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python37\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

The file starts with { and has '' for values.It has many values and large in size.

Dummy type: {'abc': 'abc', 'abc': 2, 'abc': 123123, 'abc': 21, 'abc': 'abc', 'abc': 'abc'} like this many more rows

  • 3
    Can you paste the json file somewhere? – orestisf Jul 09 '20 at 06:31
  • 2
    Does this answer your question? [Python/Json:Expecting property name enclosed in double quotes](https://stackoverflow.com/questions/39491420/python-jsonexpecting-property-name-enclosed-in-double-quotes) – sushanth Jul 09 '20 at 06:31
  • No it doesn't solve my problem @Sushanth – Nikhil Tiwari Jul 09 '20 at 06:36
  • 1
    You would need to include the json file content for a precise solution. – sushanth Jul 09 '20 at 06:38
  • @orestisf i cannot paste it here – Nikhil Tiwari Jul 09 '20 at 06:40
  • 1
    Your file seems to start with a `{`. In JSON the next expected non-whitespace character is a `"` or `}`. Your file does not follow this rule and can't be parsed a JSON. – Klaus D. Jul 09 '20 at 06:42
  • 1
    Edit the question, don't add it as a comment! – Klaus D. Jul 09 '20 at 06:43
  • You oeed to provide a [mre] which probably entails reducing the JSON data to the smallest fragment which reproduces the failure. (The error message looks like you can reduce it to maybe five bytes.) Chances are you will figure out what's wrong on your own, at which point probably simply delete this question. – tripleee Jul 09 '20 at 06:45
  • https://meta.stackoverflow.com/questions/379403/problematic-questions-about-decoding-errors is about character-set encoding problems, but some parts of it apply here too. – tripleee Jul 09 '20 at 06:49
  • You could create a dummy replica of your file and share a part of it. Without a reference data, it's a never ending story to find the exact bug – JALO - JusAnotherLivngOrganism Jul 09 '20 at 06:51
  • @tripleee i have added all the details about the file that i can so why do you need to close this and i am learning things so there is nothing else that i can describe about it – Nikhil Tiwari Jul 09 '20 at 06:54
  • 1
    The question can absolutely be reopened once you share enough data to allow us to help you figure out what's wrong. (See also [help.)](https://stackoverflow.com/help/deleted-questions) You haven't added enough yet, though. If you can show maybe the first ten characters of the file, we can probably at least tell you what we all already suspect, namely that what you have isn't JSON at all. Maybe that will even be enough to tell you what it actually is (I'm guessing at this point it's Python's `repr()` of some structure). – tripleee Jul 09 '20 at 06:58
  • Sorry, a better help link: https://stackoverflow.com/help/closed-questions – tripleee Jul 09 '20 at 07:07
  • @tripleee it was not a json file that was the issue so i replaced single commas with double and it worked thanks for the help – Nikhil Tiwari Jul 09 '20 at 07:28

1 Answers1

0

json.load expects double quotes for property names e.g.:

[{"name":"John Doe","value":1},{"name":"John Snow","value":2}]

Also, ensure that any boolean values (TRUE, FALSE) are in lower case (true, false)

You should check following too:

Expecting double quotes - 1

Expecting double quotes - 2

and importantly this : single-vs-double-quotes-in-json