1

The error "expecting value" is occurring when I'm trying to read a json file which I have created myself. The weird thing is that this used to work. I was working on another project in between and did some updates to conda and now I'm getting the error. I've searched and found similar questions but none that have been applicable in my case.

This is what I'm doing right now:

def show_json(filepath):
        with open("/Users/human/Doc/PYTHON/bn/bread/"+filepath) as f:
            k = json.load(f)
            return k

state_d = show_json("states_json.json")

Here is the error traceback:


  File "/Users/human/PYTHON/SPYDER/bn/bread/main_.py", line 55, in <module>
    state_d=show_json("states_json.json")

  File "/Users/human/PYTHON/SPYDER/bn/bread/main_.py", line 48, in show_json
    k = json.load(f)

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

And this is what the json file looks like:

{"_state_one_":None,"_state_two_":None,"_state_three_":None,"_state_four_":None}

Could something have happened while updating some libraries and packages or am I just doing something wrong code-wise?

2
  • My comment is off-topic, and the answer below is correct, but I wanted to say that for a low-reputation user, this is an excellently-written question that contains all the necessary information, and is well-formatted to boot. Hyvä! Commented Sep 21, 2020 at 21:30
  • 1
    Olen nopea oppija! Commented Sep 21, 2020 at 21:33

1 Answer 1

3

Your JSON file is simply not compliant to the JSON specifications. Shortly put, null should be used instead of None

Sign up to request clarification or add additional context in comments.

2 Comments

Quite right; to wit a useful debugging tool is jsonlint.com which will explicitly surface this kind of error.
Awesome this worked! However I'm still not sure why or how this could run without error earlier, I guess I must've made some changes that I forgot about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.