JSONDecodeError: Expecting value: line 1 column 1 (char 0)

jupyter notebook list json.decoder.jsondecodeerror: expecting value: line 1 column 1 (char 0)
raise jsondecodeerror("expecting value", s, err.value) from none
json parse error - expecting value line 1 column 1 (char 0) django
how to fix jsondecodeerror
error jsondecodeerror: expecting value: line 1 column 1
warning root expecting value: line 1 column 1 (char 0)
errormessage'': expecting value: line 1 column 1 (char 0)
json decoder jsondecodeerror expecting value line 1 column 29 char 28

I am getting error Expecting value: line 1 column 1 (char 0) when trying to decode JSON.

The URL I use for the API call works fine in the browser, but gives this error when done through a curl request. The following is the code I use for the curl request.

The error happens at return simplejson.loads(response_json)

    response_json = self.web_fetch(url)
    response_json = response_json.decode('utf-8')
    return json.loads(response_json)


def web_fetch(self, url):
        buffer = StringIO()
        curl = pycurl.Curl()
        curl.setopt(curl.URL, url)
        curl.setopt(curl.TIMEOUT, self.timeout)
        curl.setopt(curl.WRITEFUNCTION, buffer.write)
        curl.perform()
        curl.close()
        response = buffer.getvalue().strip()
        return response

Full Traceback:

Traceback:

File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/nab/Desktop/pricestore/pricemodels/views.py" in view_category
  620.     apicall=api.API().search_parts(category_id= str(categoryofpart.api_id), manufacturer = manufacturer, filter = filters, start=(catpage-1)*20, limit=20, sort_by='[["mpn","asc"]]')
File "/Users/nab/Desktop/pricestore/pricemodels/api.py" in search_parts
  176.         return simplejson.loads(response_json)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/__init__.py" in loads
  455.         return _default_decoder.decode(s)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/decoder.py" in decode
  374.         obj, end = self.raw_decode(s)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/decoder.py" in raw_decode
  393.         return self.scan_once(s, idx=_w(s, idx).end())

Exception Type: JSONDecodeError at /pricemodels/2/dir/
Exception Value: Expecting value: line 1 column 1 (char 0)

From `Expecting value: line 1 column 1 (char 0)` to `Response , 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  raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) The above exception was the direct cause of the following exception:

json.decoder.JSONDecodeError: Expecting value: line 1 , JSONDecodeError: Expecting value: line 1 column 1 (char 0) #47. Open. chandrasg opened this issue on Nov 5, 2017 · 23 comments. 2 Answers 2. json.loads() takes a JSON encoded string, not a filename. You want to use json.load() (no s) instead and pass in an open file object: The open() command produces a file object that json.load() can then read from, to produce the decoded Python object for you.

With the requests lib JSONDecodeError can happen when you have an http error code like 404 and try to parse the response as JSON !

You must first check for 200 (OK) or let it raise on error to avoid this case. I wish it failed with a less cryptic error message.

NOTE: as Martijn Pieters stated in the comments servers can respond with JSON in case of errors (it depends on the implementation), so checking the Content-Type header is more reliable.

JSONDecodeError - learnpython, JSONDecodeError: Expecting value: line 1 column 1 (char 0). I appreciate any help, Sorry I'm not more helpful this is my first time using requests and json. 1  JSONDecodeError: Expecting value: line 1 column 33 (char 32) ValueError: malformed node or string: <_ast.Name object at 0x0000016583978160> The string starts like this temp3[:50] >>> '{"firstOTDriveAlreadyHappened": False, "NeedsHomeA'

I think it's worth mentioning that in cases where you're parsing the contents of a JSON file itself - sanity checks can be useful to ensure that you're actually invoking 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'm a little embarrassed to admit that this can happen sometimes:

contents = json.loads(json_file_path)

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 , JSONDecodeError: Expecting value: line 1 column 1 (char 0). When parsing a webpage this error happens once in a while and causes my script  JSONDecodeError: Expecting value: line 1 column 1 (char 0) specifically occurs when an empty string is passed to json decode – wesinat0r May 11 at 16:38 add a comment | 31

A lot of times, this will be because the string you're trying to parse is blank:

>>> import json
>>> x = json.loads("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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)

You can remedy by checking whether json_string is empty beforehand:

import json

if json_string:
    x = json.loads(json_string)
else:
    // Your logic here
    x = {}

simplejson.errors.JSONDecodeError: Expecting value: line 1 column , JSONDecodeError: Expecting value: line 1 column 1 (char 0). Hi Team,. I have installed a package called pycricbuzz from git hub (https://github. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more JSONDecodeError: Expecting value: line 1 column 1

json.decoder.JSONDecodeError: Expecting value: line 1 column 1, JSONDecodeError: Expecting value: line 1 column 1 (char 0). show message first​: File "/Library/Frameworks/Python.framework/Versions/3.7  From `Expecting value: line 1 column 1 (char 0)` to `Response content not in json format` #4908

JSONDecodeError: Expecting value: line 1 column 1 (char 0 , I am getting error Expecting value line 1 column 1 char 0 when trying to decode JSONThe URL I use for the API call works fine in the bro 126 1 1 silver badge 4 4 bronze badges This is a very interesting comment. I'm having the same issue, could you please go deeper on this method Im new on all this things.

jsondecodeerror expecting value line 1 column 1 (char 0) in python , JSONDecodeError: Expecting value: line 1 column 1 (char 0) 01:06:02 ERROR - Return code: 1 01:06:02 INFO - Setting buildbot property blobber_files to  json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #106. from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Comments
  • Last but not least, what does print repr(response_json) tell you is being passed to .loads()?
  • One more: why use simplejson when you can just use the stdlib json (which is the same library as simplejson)?
  • That is an empty string. Your web_fetch() call failed.
  • Yes, I do recommend you use something easier to use than pycurl. requests offers a far easier API, especially when it comes to debugging what is going on. Unless you specifically have to have a newer version of the simplejson library, just stick with json, saves you a dependency to manage.
  • is response_json the return value of .json()? Then you already have decoded data and don't need to use json.loads() anymore. response decoded it for you.
  • I am getting this same error using requests! The trace seems to suggest that requests uses complexjson, which uses simplejson. Weird.
  • @Rayu: requests will use simplejson if available; some people want to use the latest simplejson release rather than the one bundled with the Python stdlib.
  • "There is no need to use simplejson library, the same library is included with Python as the json module."... I respectfully disagree. simplejson uses the built-in json under the hood, but gives more descriptive errors. In this case using json would just give you a generic ValueError: No JSON object could be decoded.
  • Could this be caused by an abort or incomplete json ? I get this randomly once in a while, not sure how to reproduce it.
  • @ChristopheRoussy: yes, that's rather the point of the question (the OP got an empty u'' response). Your JSONDecodeError tells you much data was successfully parsed before it ran into an error; that can be because there is invalid data at that point (malformed or corrupted JSON document) or because the data was truncated.
  • In the comments it was clear the OP got an empty response. Since requests.get(url).json() Just Works, the JSON isn't malformed either.