A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-difference-between-json-load-and-json-loads/ below:

Difference Between json.load() and json.loads() - Python

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:

Example: First creating the json file: Python
import json

data = {
    "name": "Satyam kumar",
    "place": "patna",
    "skills": [
        "Raspberry pi",
        "Machine Learning",
        "Web Development"
    ],
    "email": "xyz@gmail.com",
    "projects": [
        "Python Data Mining",
        "Python Data Science"
    ]
}
with open( "data_file.json" , "w" ) as write:
    json.dump( data , write )

Output:

data_file.json

After, 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': 'xyz@gmail.com', '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:

Example: Let's parse a JSON string using json.loads(): Python
import json 
  
# JSON string: 
data = """{ 
    "Name": "Jennifer Smith", 
    "Contact Number": 7867567898, 
    "Email": "jen123@gmail.com", 
    "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': 'jen123@gmail.com',

'Hobbies': ['Reading', 'Sketching', 'Horse Riding']

}



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4