Using the following code I was able to open your JSON and print it. Save your JSON to temp.json and try this:

import json

with open("temp.json", "r") as infile:
    data = json.loads(infile.read())

print(data)
Answer from mikeg on Stack Overflow
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
1 month ago - As a result of this, if a dictionary is converted into JSON and then back into a dictionary, the dictionary may not equal the original one. That is, loads(dumps(x)) != x if x has non-string keys.
Discussions

python - Handle JSON Decode Error when nothing returned - Stack Overflow
The original question was about ... raise JSONDecodeError on bad input. See your earlier link. 2015-06-15T12:13:57.403Z+00:00 ... @JulieinAustin: I would do otherwise, since it is actually... standard library. If you are not concerned about speed too much, I would use what is already available. Yes, simplejson does this in a more fine-grained way, but it has its own issues. What would you say if the try...except block would only encapsulate json.loads ... More on stackoverflow.com
🌐 stackoverflow.com
Bug: `JSONDecodeError` when trying to load JSON with an array at the top-level
File "/tmp/archivebox/venv/lib... "/usr/lib/python3.11/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: ... More on github.com
🌐 github.com
7
February 15, 2024
Help: json.loads() cannot parse valid json
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode obj, end = ... More on discuss.python.org
🌐 discuss.python.org
0
0
December 17, 2021
Why am I getting a JSONDecodeError when trying to load a JSON file in Python? - Stack Overflow
I'm trying to load a JSON file in to Python, but it's giving me an JSONDecodeError error which seems to suggest the file is empty... which I know is not true. I've reviewed similar questions I can ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.

🌐
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 ...
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
🌐
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 - So we see the json.decoder throwing a JSONDecodeError. A common way in Python scripts is to use try + except to catch errors. The "try" part runs the code you want to run, in this case the json.loads line.
🌐
Career Karma
careerkarma.com › blog › python › python jsondecodeerror explanation and solution
Python JSONDecodeError Explanation and Solution | CK
December 1, 2023 - For example, your JSON data may be missing a curly bracket, or have a key that does not have a value, or be missing some other piece of syntax. To completely fix a JSONDecodeError, you need to go into a JSON file to see what the problem is.
🌐
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 - File "/tmp/archivebox/venv/lib... "/usr/lib/python3.11/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: ...
Author   philippemilink
Find elsewhere
🌐
Python.org
discuss.python.org › python help
Help: json.loads() cannot parse valid json - Python Help - Discussions on Python.org
December 17, 2021 - File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/...
🌐
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)
🌐
Bobby Hadz
bobbyhadz.com › blog › python-jsondecodeerror-extra-data
json.decoder.JSONDecodeError: Extra data in Python [Solved] | bobbyhadz
April 8, 2024 - The Python "json.decoder.JSONDecodeError: Extra data" occurs when we try to parse multiple objects without wrapping them in an array.
🌐
Medium
lynn-kwong.medium.com › python-json-tricks-how-to-deal-with-jsondecodeerror-2353464814bc
Python JSON tricks: how to deal with JSONDecodeError | by Lynn G. Kwong | Medium
October 31, 2024 - A JSON looks like the dictionary type in Python, but they are different. The essential difference is that a JSON is a pure string that has a strict format. If you don’t write it properly, you may have unexpected errors.
🌐
Dot Net Perls
dotnetperls.com › json-python
Python - json: Import JSON, load and dumps - Dot Net Perls
import json # An error occurs when the JSON is invalid. result = json.loads('["invalid JSON data sorry') Traceback (most recent call last): ... json.decoder.JSONDecodeError: Unterminated string starting at: line
🌐
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...
🌐
Moon Technolabs
moontechnolabs.com › qanda › json-decoder-error
How to Resolve JSON Decoder Error?
June 6, 2025 - import json response = '' # Empty string data = json.loads(response) # Raises JSONDecodeError · Solution: Make sure the input string isn’t empty. If you’re making a request (e.g., using requests.get()), check the API response to ensure it returns valid JSON.
🌐
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 ·
🌐
Google Groups
groups.google.com › g › comp.lang.python › c › 9LBJR-UL1rc
errors with json.loads
On 9/20/2017 5:56 PM, John Gordon wrote: > In <mailman.101.1505945...@python.org> john polo <jp...@mail.usf.edu> writes: > >> JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) >> ?json.loads says that the method is for deserializing "s", with "s" >> being a string, bytes, or bytearray.
Top answer
1 of 16
322

Your code produced an empty response body; you'd want to check for that or catch the exception raised. It is possible the server responded with a 204 No Content response, or a non-200-range status code was returned (404 Not Found, etc.). Check for this.

Note:

  • There is no need to decode a response from UTF8 to Unicode, the json.loads() method can handle UTF8-encoded data natively.

  • pycurl has a very archaic API. Unless you have a specific requirement for using it, there are better choices.

Either requests or httpx offer much friendlier APIs, including JSON support.

If you can, replace your call with the following httpx code:

import httpx

response = httpx.get(url)
response.raise_for_status()  # raises exception when not a 2xx response
if response.status_code != 204:
    return response.json()

Of course, this won't protect you from a URL that doesn't comply with HTTP standards; when using arbitrary URLs where this is a possibility, check if the server intended to give you JSON by checking the Content-Type header, and for good measure catch the exception:

if (
    response.status_code != 204 and
    response.headers["content-type"].strip().startswith("application/json")
):
    try:
        return response.json()
    except ValueError:
        # decide how to handle a server that's misbehaving to this extent
2 of 16
261

Be sure to remember to invoke json.loads() on the contents of the file, as opposed to the file path of that JSON:

json_file_path = "/path/to/example.json"

with open(json_file_path, 'r') as j:
     contents = json.loads(j.read())

I think a lot of people are guilty of doing this every once in a while (myself included):

contents = json.load(json_file_path)