Difference Between json.load() and json.loads() - Python
Last Updated :
03 Jul, 2025
This article discusses the differences between two important methods: json.load() and json.loads(). Both are used to convert JSON data into Python objects, but they are used in different contexts.
json.load()
json.load() takes a file object and returns the json object. It is used to read JSON encoded data from a file and convert it into a Python dictionary and deserialize a file itself i.e. it accepts a file object.
Syntax
json.load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Parameters:
- fp: The file pointer from which to read the JSON data.
- object_hook: A function that customizes the conversion of JSON objects to Python objects.
- parse_float: A function that converts JSON float values.
- parse_int: A function that converts JSON integer values.
- object_pairs_hook: A function that converts JSON objects to an ordered dictionary.
Example: First creating the json file:
Python
import json
data = {
"name": "Satyam kumar",
"place": "patna",
"skills": [
"Raspberry pi",
"Machine Learning",
"Web Development"
],
"email": "[email protected]",
"projects": [
"Python Data Mining",
"Python Data Science"
]
}
with open( "data_file.json" , "w" ) as write:
json.dump( data , write )
Output:
data_file.jsonAfter, creating json file, let's use json.load():
Python
with open("data_file.json", "r") as read_content:
print(json.load(read_content))
Output:
{'name': 'Satyam kumar', 'place': 'patna', 'skills': ['Raspberry pi', 'Machine Learning', 'Web Development'],
'email': '[email protected]', 'projects': ['Python Data Mining', 'Python Data Science']}
json.loads()
json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary. It is mainly used for deserializing native string, byte, or byte array which consists of JSON data into Python Dictionary.
Syntax
json.loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Parameters:
- s: The string containing the JSON data to be parsed.
- object_hook: A function that customizes the conversion of JSON objects to Python objects.
- parse_float: A function that converts JSON float values.
- parse_int: A function that converts JSON integer values.
- object_pairs_hook: A function that converts JSON objects to an ordered dictionary.
Example: Let's parse a JSON string using json.loads():
Python
import json
# JSON string:
data = """{
"Name": "Jennifer Smith",
"Contact Number": 7867567898,
"Email": "[email protected]",
"Hobbies":["Reading", "Sketching", "Horse Riding"]
}"""
# parse data:
res = json.loads( data )
# the result is a Python dictionary:
print( res )
Output:
{
'Name': 'Jennifer Smith',
'Contact Number': 7867567898,
'Email': '[email protected]',
'Hobbies': ['Reading', 'Sketching', 'Horse Riding']
}
Similar Reads
Difference between json.dump() and json.dumps() - Python JSON is a lightweight data format for data interchange which can be easily read and written by humans, easily parsed and generated by machines. It is a complete language-independent text format. To work with JSON data, Python has a built-in package called json. json.dumps()json.dumps() method can co
2 min read
Difference between List and Array in Python In Python, lists and arrays are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements. In this article, we will see the difference between the two.Operations Difference in Lists and ArraysAccessi
6 min read
json.loads() vs json.loads() in Python orjson.loads() and json.loads() are both Python methods used to deserialize (convert from a string representation to a Python object) JSON data. orjson and json are both Python libraries that provide functions for encoding and decoding JSON data. However, they have some differences in terms of perfo
4 min read
Difference between List and Dictionary in Python Lists and Dictionaries in Python are inbuilt data structures that are used to store data. Lists are linear in nature whereas dictionaries stored the data in key-value pairs. In this article, we will see the difference between the two and find out the time complexities and space complexities which ar
6 min read
What Is The Difference Between .Py And .Pyc Files? When working with Python, you might have come across different file extensions like .py and .pyc. Understanding the differences between these two types of files is essential for efficient Python programming and debugging. '.py' files contain human-readable source code written by developers, while '.
3 min read
What is the difference between Python's Module, Package and Library? In this article, we will see the difference between Python's Module, Package, and Library. We will also see some examples of each to things more clear. What is Module in Python? The module is a simple Python file that contains collections of functions and global variables and with having a .py exten
2 min read