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
Answer from Martijn Pieters on Stack Overflow
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)
🌐
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
When you see the error message "Expecting value: line 1 column 1 (char 0)", it means your program attempted to parse a JSON string but found nothing or invalid content right at the beginning.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-json-decoder-jsondecodeerror-expecting-value-line-1-column-1-char-0
JSONDecodeError: Expecting value: line 1 column 1 (char 0) | bobbyhadz
The json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) occurs when we try to parse something that is not valid JSON as if it were.
🌐
GitHub
github.com › AUTOMATIC1111 › stable-diffusion-webui › discussions › 4374
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) · AUTOMATIC1111/stable-diffusion-webui · Discussion #4374
Solved it by deleting some config files. This will reset all of the settings you've set before. You might want to check if one of the files has size 0, that might be the only file that needs to be deleted.
Author   AUTOMATIC1111
🌐
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.

🌐
Frappe
discuss.frappe.io › erpnext
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) - ERPNext - Frappe Forum
January 25, 2022 - Hi there, For a few days I’m facing with this issue: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) I’m in production, and trying to move an entire website using export fixtures. I created an…
🌐
Python Pool
pythonpool.com › home › blog › [fixed] jsondecodeerror: expecting value: line 1 column 1 (char 0)
[Fixed] JSONDecodeError: Expecting Value: Line 1 column 1 (char 0)
April 15, 2022 - JSONDecodeError means there is an incorrect JSON format being followed. For instance, the JSON data may be missing a curly bracket, have a key that does not have a value, and data not enclosed within double-quotes or some other syntactic error.
🌐
Django Forum
forum.djangoproject.com › using django › forms & apis
What does this django error mean? JSONDecodeError at '/url-path/' Expecting value: line 1 column 1 (char 0) - Forms & APIs - Django Forum
May 13, 2023 - I frequently encounter this problem when using Django and Python in general; it seems to occur everytime I attempt to make an api call or other similar operation. I am trying to onboard users to PayPal in this case utilizing the PayPal “Referral API,” and after following the documentation, I came up with the following code. def onboard_seller_view_2(request): # Retrieve seller's information from the request seller_name = request.POST.get('name') seller_email = request.POST.get('ema...
🌐
Esri Support
support.esri.com › en-us › knowledge-base › error-json-decoder-jsondecodererror-expecting-value-lin-000024610
Error: json.decoder.JSONDecoderError:Expecting Value: Line 1 Column 1
August 24, 2024 - Running an ArcGIS API for Python script that requires signing in to Portal for ArcGIS may fail and return the following error:Error:json.decoder.JSONDecoderError:Expecting value: line 1 column 1
Find elsewhere
🌐
sebhastian
sebhastian.com › python-jsondecodeerror-expecting-value
JSONDecodeError: Expecting value: line 1 column 1 (char 0) | sebhastian
February 1, 2023 - A JSONDecodeError: Expecting value: line 1 column 1 (char 0) when running Python code means you are trying to decode an invalid JSON string.
🌐
GitHub
github.com › AUTOMATIC1111 › stable-diffusion-webui › issues › 8836
[Bug]: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) · Issue #8836 · AUTOMATIC1111/stable-diffusion-webui
March 23, 2023 - Is there an existing issue for this? I have searched the existing issues and checked the recent builds/commits What happened? a1111 was working fine, was generating images, it froze... on starting it again I get this, can't seem to find ...
Author   tenabraex
🌐
Streamlit
discuss.streamlit.io › using streamlit
json.decoder.JSONDecodeError - Using Streamlit - Streamlit
March 19, 2021 - My Streamlit App was working fine till the last week. But, when I tried to use it today, I see a weird error called “json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)”. Initially, I deployed in Hero…
🌐
Position Is Everything
positioniseverything.net › home › json.decoder.jsondecodeerror: expecting value: line 1 column 1 (char 0)
Json.decoder.jsondecodeerror: Expecting Value: Line 1 Column 1 (Char 0) - Position Is Everything
December 29, 2025 - The programming error “json.decoder.jsondecodeerror: Expecting value: line 1 column 1 (char 0)” occurs due to incompatible character encoding and usage of non-JSON conforming quoting.
🌐
GitHub
github.com › psf › requests › issues › 4908
From `Expecting value: line 1 column 1 (char 0)` to `Response content not in json format` · Issue #4908 · psf/requests
December 13, 2018 - Hi! Please run import requests r = requests.get('http://httpbin.org/status/200') r.status_code r.json() The answer is: 200 JSONDecodeError: Expecting value: line 1 column 1 (char 0) I do not think it is informative and maybe it could con...
Author   SebastianoF
🌐
Hugging Face
huggingface.co › CohereLabs › aya-101 › discussions › 10
CohereLabs/aya-101 · JSONDecodeError: Expecting value: line 1 column 1 (char 0)
335 336 """ --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end() 339 if end != len(s): File /opt/anaconda3/envs/gpt/lib/python3.10/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end · JSONDecodeError: Expecting value: line 1 column 1 (char 0) viraat Feb 20, 2024 ·
🌐
Anki
forums.ankiweb.net › help
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) - Help - Anki Forums
June 30, 2020 - I’ve been using anki for a couple of years. I did something that erased backside of all cards. I tried to fix it but caused more problems. So I tried to download a new version of anki. I think I’ve lost all my cards bu…
🌐
W3docs
w3docs.com › python
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
It could happen due to: The input string is empty. The input string is not a valid JSON format, it may contain additional characters or syntax errors. The input is not a string at all, but another data type such as an int, float or None.
🌐
Edureka Community
edureka.co › home › community › categories › python › jsondecodeerror expecting value line 1 column 1...
JSONDecodeError Expecting value line 1 column 1 char 0 | Edureka Community
May 9, 2022 - JSONDecodeError Expecting value line 1 column 1... Reading different format files from s3 having decoding issues using boto3 May 17, 2024
🌐
Python Forum
python-forum.io › thread-27359.html
expecting value: line 1 column 1 (char 0) in print (r.json))
hi i experience a problem. So i deploy a model in flask from flask import Flask, request, jsonify#--jsonify will return the data from keras.models import load_model import numpy as np import pandas as pd #creates the web service running on port 12...