JSON stands for JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the Python JSON package into Python script. The text in JSON is done through quoted-string which contains a value in key-value mapping within { }. It is similar to the dictionary in Python.
Function Used
json.load(): json.load() function is present in Python built-in ‘JSON’ module. This function is used to parse the JSON string.
json.loads(): json.loads() function is present in Python built-in ‘json’ module. This function is used to parse the JSON string.
Convert JSON String to Dictionary Python
In this example, we are going to convert a JSON string to Python Dictionary using json.loads() method of JSON module in Python. Firstly, we import json module and then define JSON string after that converting JSON string to Python dictionary by passing it to json.loads() in parameter. We have print the dictionary and their values using the keys as seen in the output.
Python3
import json
jsonString = '{ "id": 121, "name": "Naveen", "course": "MERN Stack"}'
student_details = json.loads(jsonString)
print (student_details)
print (student_details[ 'name' ])
print (student_details[ 'course' ])
|
Output{'id': 121, 'name': 'Naveen', 'course': 'MERN Stack'}
Naveen
MERN Stack
Convert JSON File to Python Object
Below is the JSON file that we will convert to Python dictionary using json.load() mehtod.

In the below code, firstly we open the “data.json” file using file handling in Python and then convert the file to Python object using the json.load() method we have also print the type of data after conversion and print the dictionary.
Python3
import json
with open ( 'data.json' ) as json_file:
data = json.load(json_file)
print ( "Type:" , type (data))
print ( "\nPeople1:" , data[ 'people1' ])
print ( "\nPeople2:" , data[ 'people2' ])
|
Output :

Convert Nested JSON Object to Dictionary
In this example, we will convert the nested JSON into a Python dictionary. For JSON data we will use the same JSON file used in the above example.
Python3
import json
with open ( 'data.json' ) as json_file:
data = json.load(json_file)
print (data[ 'people1' ][ 0 ])
print ( "\nPrinting nested dictionary as a key-value pair\n" )
for i in data[ 'people1' ]:
print ( "Name:" , i[ 'name' ])
print ( "Website:" , i[ 'website' ])
print ( "From:" , i[ 'from' ])
print ()
|
Output :

Convert JSON String to Dictionary in Python
In this example, we will convert the json string into Python dictionary using json.loads() method. Firstly, we will import JSON module. Create a json string and store it in a variable ‘json_string’ after that we will convert the json string into dictionary by passing ‘json_string’ into json.loads() as argument and store the converted dictionary in ‘json_dict’. Finally, print the Python dictionary.
Python3
import json
json_string = '{"Name": "Suezen", "age": 23, "Course": "DSA"}'
json_dict = json.loads(json_string)
print (json_dict)
|
Output{'Name': 'Suezen', 'age': 23, 'Course': 'DSA'}