Function Used:
Syntax: json.load(file_name)
Parameter: It takes JSON file as the parameter.
Return type: It returns the python dictionary object.
# Python program to demonstrate
# Conversion of JSON data to
# dictionary
# importing the module
import json
# Opening JSON file
with open('data.json') as json_file:
data = json.load(json_file)
# Print the type of data variable
print("Type:", type(data))
# Print the data of dictionary
print("\nPeople1:", data['people1'])
print("\nPeople2:", data['people2'])
# Python program to demonstrate
# Conversion of JSON data to
# dictionary
# importing the module
import json
# Opening JSON file
with open('data.json') as json_file:
data = json.load(json_file)
# for reading nested data [0] represents
# the index value of the list
print(data['people1'][0])
# for printing the key-value pair of
# nested dictionary for looop can be used
print("\nPrinting nested dicitonary as a key-value pair\n")
for i in data['people1']:
print("Name:", i['name'])
print("Website:", i['website'])
print("From:", i['from'])
print()
Comments