Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Valueerror: No json object could be decoded - simple solution when encountering the error.
Next
Answered
Emily Davies
  • 20
Emily Davies
Asked: May 18, 20222022-05-18T16:03:43+00:00 2022-05-18T16:03:43+00:00In: python

Valueerror: No json object could be decoded – simple solution when encountering the error.

  • 20

. Advertisement .

..3..

. Advertisement .

..4..

I have the following python code, but I do not know how to find the correct result. Why has this problem occurred, and how can it be solved? Here is the code that I am running:

with open(filename, "r") as f:
  data = json.loads(f.read())
with open(filename, "r") as f:
  data = json.load(f)

And this is the error text I receive:

Traceback (most recent call last):
  File "myfile.py", line 8, in myfunction
  config = json.loads(f.read())
  File "c:\python27\lib\json\__init__.py", line 326, in loads
  return _default_decoder.decode(s)
  File "c:\python27\lib\json\decoder.py", line 360, in decode
  obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\python27\lib\json\decoder.py", line 378, in raw_decode
  raise ValueError("No JSON object could be decoded")
 ValueError: No JSON object could be decoded
no json object could be decoded
  • 2 2 Answers
  • 175 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-14T09:32:59+00:00Added an answer on June 14, 2022 at 9:32 am

    The cause: In many circumstances when the built-in json module is unclear, I’ve found that the simplejson module produces more descriptive errors. For example, there’s a comma after the last entry in a list:

    json.loads('[1,2,]')
    ....
    ValueError: No JSON object could be decoded

    Also with simplejson:

    simplejson.loads('[1,2,]') 
    ...
    simplejson.decoder.JSONDecodeError: Expecting object: line 1 column 5 (char 5)

    Solution: After I use sudo pip install simplejson to install simplejson.

    And then, the error is figured out.

    import json
    import simplejson
    
    
    def test_parse_json():
    f_path = '/home/hello/_data.json'
    with open(f_path) as f:
    # j_data = json.load(f) # ValueError: No JSON object could be decoded
    j_data = simplejson.load(f) # right
    lst_img = j_data['images']['image']
    print lst_img[0]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Manon Morel
    2022-05-25T20:28:13+00:00Added an answer on May 25, 2022 at 8:28 pm

    It won’t be possible to get Python to correct the JSON. To find a linter online, you will need one .

    This will indicate any errors in the JSON that you are trying decode.

    • 13
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.