Convert Json Data to Python Object-DecodingDevOps

Convert Json Data to Python Object

JSON  stands for JavaScript Object Notation is a syntax for storing and exchanging the data it is a text, written with JavaScript Object Notation. it is a common data format used for browser-server communication. In these criteria we use JSON.loads() function to convert the JSON data to python objects. This JSON.loads() method is used to decode the  JSON string.

import json

json_object = '{ "Name":"harish", "Class":"8", "Age":"12" }'

python_object = json.loads(json_object)

print(python_object)

print("\nName: ",python_object["Name"])

print("Class: ",python_object["Class"])

print("Age: ",python_object["Age"])

STEP 1: Importing the JSON module in this step to get the JSON.loads function

STEP 2: Creating a JSON object which consist of the key-value attributes.

STEP 3:  Now converting the JSON Data into the python object using the JSON.loads() function which is used to decode the JSON string.

STEP 4: After converting into a python object assign it to a variable in this context.

STEP 5:  Now print the variable that is the python object which is acquired from the JSON data. 

 

OUTPUT:

JSON data:
{'Name': 'Harish', 'Class': '8', 'Age': "12"}

Name:  Harish
Class:  8
Age:  12

Leave a Reply

Your email address will not be published. Required fields are marked *