Module ‘json’ has no attribute ‘loads’ ( Solved )

Module 'json' has no attribute 'loads'

JSON stands for JavaScript Object Notation. Most developers use it for building endpoints for their web applications. Once you have created an API with endpoints then you can use it in many applications like web applications, mobile apps e.t.c. But while coding you can get the error like module ‘json’ has no attribute ‘loads‘. If you are getting this error then this post is for you.

In this entire tutorial, you will learn how to solve this AttributeError in a simple way.

Cause of AttributeError: module ‘json’ has no attribute ‘loads’

The main cause for getting this error is when you use the same name for your project file and the Python default module. To parse JSON data in python you have to use the JSON module. But there is a conflict between your current directory file name JSON with the JSON module.

When I will run the below lines of code then I will get the module ‘json’ has no attribute ‘loads’ error as the filename for the code written is “json.py”.

import json
jsonData = """{"name":"Rob","age":35}"""

data = json.loads(jsonData)
print(data)

Output

module json has no attribute loads
module json has no attribute loads error

 

Solution for the module ‘json’ has no attribute ‘loads’ Error

The solution for the AttributeError is very simple. The error was coming because you were using the same file name “json.py” as the default module JSON. It was conflicting. So to remove the error you have to remove or rename the filename for your current directory.

Now if I run the same above code then I will not get the error.

import json
jsonData = """{"name":"Rob","age":35}"""

data = json.loads(jsonData)
print(data)

Output

Not getting json loads error
Not getting json loads error

Conclusion

Most of the time you get Json AttributeError when you are using the same file name as the JSON module. The above AttributeError was an example of it. Even if the problem persists then you have to again reinstall the json module to remove the error.

I hope the above solution has worked for you. If you have any doubts or suggestions then you can contact us for more help.

 

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner