Friday, October 3, 2025
HomeLanguagesDeserialize JSON to Object in Python

Deserialize JSON to Object in Python

Let us see how to deserialize a JSON document into a Python object. Deserialization is the process of decoding the data that is in JSON format into native data type. In Python, deserialization decodes JSON data into a dictionary(data type in python).
We will be using these methods of the json module to perform this task : 
 

  • loads() : to deserialize a JSON document to a Python object.
  • load() : to deserialize a JSON formatted stream ( which supports reading from a file) to a Python object.

Example 1 : Using the loads() function. 
 

Python3




# importing the module
import json
 
# creating the JSON data as a string
data = '{"Name" : "Romy", "Gender" : "Female"}'
 
print("Datatype before deserialization : "
      + str(type(data)))
  
# deserializing the data
data = json.loads(data)
 
print("Datatype after deserialization : "
      + str(type(data)))


Output : 
 

Datatype before deserialization : 
Datatype after deserialization : 

Example 2 : Using the load() function. We have to deserialize a file named file.json. 
 

 

Python3




# importing the module
import json
 
# opening the JSON file
data = open('file.json',)
 
print("Datatype before deserialization : "
      + str(type(data)))
    
# deserializing the data
data = json.load(data)
 
print("Datatype after deserialization : "
      + str(type(data)))


Output : 
 

Datatype before deserialization : 
Datatype after deserialization : 

 

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS