Just to make more clear the comment of @tim, in python3 you can just write

from json import JSONDecodeError

No need for simplejson package

Answer from George Bikas on Stack Overflow
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
1 month ago - JSONDecodeError – When the data being deserialized is not a valid JSON document.
Discussions

ImportError: cannot import name 'JSONDecodeError'
Steps to reproduce: Running python 3.4.2 on Debian GNU/Linux 8 (jessie). Installed with pip3 install bunq_sdk --upgrade Run test.py which contains from bunq.sdk import context What happens: ~ $ pyt... More on github.com
🌐 github.com
5
August 2, 2018
JSONDecodeError after updating conda
After the update, I am getting ... ( File "/anaconda/lib/python3.8/site-packages/conda/exceptions.py", line 16, in from requests.exceptions import JSONDecodeError ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' (/anaconda/lib/python3.8/site-p... More on github.com
🌐 github.com
8
November 17, 2023
python - Python3: unable to import JSONDecodeError from json.decoder - Stack Overflow
I setup virtualenv using python 3.4.3 and tried to import JSONDecodeError from json.decoder from json.decoder import JSONDecodeError (I think its valid in python3 ? But why not working for me ?) ... More on stackoverflow.com
🌐 stackoverflow.com
Bug: `JSONDecodeError` when trying to load JSON with an array at the top-level
With ArchiveBox version 0.6.2, I used to import URLs stored in JSON files with content looking like the following: [ {"url": "https://archivebox.io/", "tags": "test,archivebox"}, {"url": "https://en.wikipedia.org/wiki/Linux", "tags": "test,wikipedia"} ] ... Everything worked well. With version 0.7.2, however, I have a JSONDecodeError ... More on github.com
🌐 github.com
7
February 15, 2024
🌐
Peterbe.com
peterbe.com › plog › jsondecodeerror-in-requests.get.json-python-2-and-3
Cope with JSONDecodeError in requests.get().json() in Python 2 and 3 - Peterbe.com
My immediate thought was why not do something like this, but then I thought for the sake of repetition and clarity your solution makes more sense. import json import requests response = requests.get(url) try: print(response.json()) except (json.decoder.JSONDecodeError, ValueError): print("N'est pas JSON")
🌐
GitHub
github.com › bunq › sdk_python › issues › 72
ImportError: cannot import name 'JSONDecodeError' · Issue #72 · bunq/sdk_python
August 2, 2018 - ~ $ python3 test.py Traceback (most recent call last): File "test.py", line 1, in <module> from bunq.sdk import context File "/usr/local/lib/python3.4/dist-packages/bunq/sdk/context.py", line 6, in <module> from bunq.sdk.model import core File "/usr/local/lib/python3.4/dist-packages/bunq/sdk/model/core.py", line 1, in <module> from bunq.sdk import client File "/usr/local/lib/python3.4/dist-packages/bunq/sdk/client.py", line 2, in <module> from json import JSONDecodeError ImportError: cannot import name 'JSONDecodeError'
Author   jeroenmeulenaar
🌐
GitHub
github.com › conda › conda › issues › 13344
JSONDecodeError after updating conda · Issue #13344 · conda/conda
November 17, 2023 - After the update, I am getting ... ( File "/anaconda/lib/python3.8/site-packages/conda/exceptions.py", line 16, in from requests.exceptions import JSONDecodeError ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' (/anaconda/lib/python3.8/site-p...
Author   ShadeAlsha
🌐
Streamsets
community.streamsets.com › community-articles-and-got-a-question-7 › importerror-cannot-import-name-jsondecodeerror-from-requests-exceptions-2033
ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' | StreamSets Community
October 19, 2023 - Solution for this is manually we are replacing line “from requests.exceptions import HTTPError, JSONDecodeError” with “from json import JSONDecodeError”
🌐
Snyk
snyk.io › advisor › simplejson › functions › simplejson.jsondecodeerror
How to use the simplejson.JSONDecodeError function in simplejson | Snyk
def _to_json(data): try: content = simplejson.loads(data) return content except JSONDecodeError: raise JSONDecodeError('Error decoding data', data, 0) torn8o / Home-AssistantConfig / custom_components / media_player / alexa.py View on Github · self._session.cookies = cookies get_resp = self._session.get('https://alexa.' + self._url + '/api/devices-v2/device') # with open(self._debugget, mode='wb') as localfile: # localfile.write(get_resp.content) try: from json.decoder import JSONDecodeError from simplejson import JSONDecodeError as SimpleJSONDecodeError # Need to catch both as Python 3.5 appears to use simplejson except ImportError: JSONDecodeError = ValueError try: get_resp.json() except (JSONDecodeError, SimpleJSONDecodeError) as ex: # ValueError is necessary for Python 3.5 for some reason template = ("An exception of type {0} occurred."
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › python › python jsondecodeerror explanation and solution
Python JSONDecodeError Explanation and Solution | CK
December 1, 2023 - In this guide, we’re going to talk about the causes of a JSONDecodeError and how to fix this error.
🌐
ProgramCreek
programcreek.com › python › example › 95917 › json.JSONDecodeError
Python Examples of json.JSONDecodeError
def login(server, username, password, alias) -> None: data = { "username": username, "password": password, } try: with urlopen(f"{server}/_matrix/maubot/v1/auth/login", data=json.dumps(data).encode("utf-8")) as resp_data: resp = json.load(resp_data) config["servers"][server] = resp["token"] if not config["default_server"]: print(Fore.CYAN, "Setting", server, "as the default server") config["default_server"] = server if alias: config["aliases"][alias] = server save_config() print(Fore.GREEN + "Logged in successfully") except HTTPError as e: try: err = json.load(e) except json.JSONDecodeError: err = {} print(Fore.RED + err.get("error", str(e)) + Fore.RESET)
🌐
GitHub
github.com › ArchiveBox › ArchiveBox › issues › 1347
Bug: `JSONDecodeError` when trying to load JSON with an array at the top-level · Issue #1347 · ArchiveBox/ArchiveBox
February 15, 2024 - With ArchiveBox version 0.6.2, I used to import URLs stored in JSON files with content looking like the following: [ {"url": "https://archivebox.io/", "tags": "test,archivebox"}, {"url": "https://en.wikipedia.org/wiki/Linux", "tags": "test,wikipedia"} ] archivebox add --parser json < ./links.json · Everything worked well. With version 0.7.2, however, I have a JSONDecodeError exception during the import: File "/tmp/archivebox/venv/lib/python3.11/site-packages/archivebox/main.py", line 631, in add new_links += parse_links_from_source(write_ahead_log, root_url=None, parser=parser) ^^^^^^^^^^^^^^
Author   philippemilink
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-parsing-errors-in-python
JSON Parsing Errors in Python - GeeksforGeeks
July 23, 2025 - JSONDecodeError is an error that occurs when the JSON data is invalid, such as having missing or extra commas, missing brackets, or other syntax errors. This error is typically raised by the json.loads() function when it's unable to parse the ...
🌐
Lightrun
lightrun.com › answers › jmathai-elodie-import-fails-jsondecoderjsondecodeerror
Import Fails: json.decoder.JSONDecodeError
Also, the print(_file) should output the file that is being imported before failing. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/jmathai/elodie/issues/251#issuecomment-336587339, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABgWCnOokpA1VdQOqOzkeaigQeK9WHIPks5sr-zcgaJpZM4Phx7w. ... I couldn’t sorry. Read more comments on GitHub > ... The solution: json raises a ValueError instead of JSONDecodeError, but JSONDecodeError (raised by simplejson ) is a subclass of ValueError.
🌐
Reddit
reddit.com › r/learnpython › i get an error whenever i try to use "json.load"
r/learnpython on Reddit: I get an error whenever I try to use "json.load"
August 8, 2022 -

JSON doc:

{
    "Data" : [
        "input1",
        "input2",
        "input3",
        "input4"
    ]
}

Python code:

import json
with open("data.json", 'r') as f:
    json_data = json.load(f)
print(json_data)

Error message:

sh-5.1$ /bin/python /home/USER/Documents/Python/learning
Traceback (most recent call last):
  File "/home/USER/Documents/Python/learning", line 27, in <module>
    json_data = json.load(f)
  File "/usr/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Disproved theories: Improper syntax (python), document not located, bad formatting (json), accidental empty space in json.

I get this error each time I try to use "json.load" so long as it has a valid parameter input. Whether read or write; error. I'm using Visual Studio Code on Linux Mint in case that matters.

Thanks for your time! I'll be happy to answer questions in the morning when I wake up.

EDIT: Clarity, and reddit dislikes my use of backticks. Manually tabbed code.

EDIT: This code SHOULD work. It does on other computers. But it doesn't on mine, and I don't know why nor how to fix it.

Top answer
1 of 2
240

There is a rule in Python programming called "it is Easier to Ask for Forgiveness than for Permission" (in short: EAFP). It means that you should catch exceptions instead of checking values for validity.

Thus, try the following:

try:
    qByUser = byUsrUrlObj.read()
    qUserData = json.loads(qByUser).decode('utf-8')
    questionSubjs = qUserData["all"]["questions"]
except ValueError:  # includes simplejson.decoder.JSONDecodeError
    print('Decoding JSON has failed')

EDIT: Since simplejson.decoder.JSONDecodeError actually inherits from ValueError (proof here), I simplified the catch statement by just using ValueError.

2 of 2
55

If you don't mind importing the json module, then the best way to handle it is through json.JSONDecodeError (or json.decoder.JSONDecodeError as they are the same) as using default errors like ValueError could catch also other exceptions not necessarily connected to the json decode one.

from json.decoder import JSONDecodeError


try:
    qByUser = byUsrUrlObj.read()
    qUserData = json.loads(qByUser).decode('utf-8')
    questionSubjs = qUserData["all"]["questions"]
except JSONDecodeError as e:
    # do whatever you want

//EDIT (Oct 2020):

As @Jacob Lee noted in the comment, there could be the basic common TypeError raised when the JSON object is not a str, bytes, or bytearray. Your question is about JSONDecodeError, but still it is worth mentioning here as a note; to handle also this situation, but differentiate between different issues, the following could be used:

from json.decoder import JSONDecodeError


try:
    qByUser = byUsrUrlObj.read()
    qUserData = json.loads(qByUser).decode('utf-8')
    questionSubjs = qUserData["all"]["questions"]
except JSONDecodeError as e:
    # do whatever you want
except TypeError as e:
    # do whatever you want in this case
🌐
Reddit
reddit.com › r/aws › eb deploy failing - importerror: cannot import name jsondecodeerror
r/aws on Reddit: eb deploy failing - ImportError: cannot import name JSONDecodeError
October 13, 2020 -

I took over a project that had its own CI pipeline already set up. This pipeline has been working fine for the last few weeks until today.

When running eb deploy --staged my-branch-name I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/eb", line 5, in <module>
    from ebcli.core.ebcore import main
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/ebcore.py", line 19, in <module>
    from ebcli.core import ebglobals, base, hooks
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/hooks.py", line 20, in <module>
    from ebcli.core import fileoperations
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/fileoperations.py", line 32, in <module>
    from json import load, JSONDecodeError
ImportError: cannot import name JSONDecodeError 

I'm somewhat unsure of what to do here. I haven't changed anything relating to CI or any of the AWS/EB configuration files.

The pipeline uses python 2.7 which according to the ebcli docs is still supported. I've tried rerunning a few times now but always get the same result. The last successful deploy with this pipeline was 3 days ago, on Wednesday.

Has anyone seen this error before or have any suggestions on how I could go about debugging it?

EDIT: It seems the awsebcli had an update the day after my last successful deploy. The changelogs don't hint at anything that would break my setup, but I think this may be the cause.

EDIT2: Locking the awsebcli to the previous version has fixed it for now. Hopefully i can get budget to slot in an upgrade to the pipeline and fix this issue once and for all. Thanks for the help everyone who commented, it's much appreciated as always.

🌐
Claudia Kuenzler
claudiokuenzler.com › blog › 1394 › how-to-handle-json-decode-error-python-script-try-except
How to handle JSON decode error in Python script with try and except
February 20, 2024 - This error: >> NameError: name 'JSONDecodeError' is not defined Indicates that JSONDecodeError has not been imported.
🌐
Python.org
discuss.python.org › ideas
JSONDecodeError exception's message - verbose - Ideas - Discussions on Python.org
July 17, 2024 - Issue One of the porposes of exception’s message is to help the developer to identify the root cause of the bug and fix it. Currently, JSONDecodeError doesn’t do it well enough. Consider the following example: import json import requests try: server_raw_response = requests.get(url) server_json_response = json.loads(server_raw_response) except JSONDecodeError as error: print(error) # JSONDecodeError: Expecting , delimiter: line 1 column 23 (char 22) Can you understand what is th...
🌐
GitHub
github.com › r0oth3x49 › ghauri › issues › 137
ImportError with Ghauri Package · Issue #137 · r0oth3x49/ghauri
October 27, 2023 - The ImportError suggests that the JSONDecodeError cannot be imported from the simplejson module. The error occurs within the Ghauri package, specifically in the common/lib.py file, indicating a dependency on the simplejson module.
Author   RytheX0o0
🌐
Techstaunch
techstaunch.com › blogs › json-decoder-jsondecodeerror-expecting-value-line-1-column-1-char-0-how-to-solve
json.decoder.jsondecodeerror: expecting value: line 1 column 1 (char 0) How to Fix, Solve
August 21, 2024 - 1import json 2from typing import Optional, Dict, Any 3 4def parse_json_data(data: str) -> Optional[Dict[str, Any]]: 5 """ 6 Safely parse JSON data with comprehensive error handling. 7 """ 8 try: 9 if not data.strip(): 10 return None 11 return json.loads(data) 12 except json.JSONDecodeError as e: 13 print(f"Failed to parse JSON: {e}") 14 return None