How to convert JSON to object in Python

1 Answer

0 votes
import json

json_obj = '{ "Name":"R2D3", "Code":"Python", "Age":60 }'

python_obj = json.loads(json_obj)

print(python_obj)

print("\nName:", python_obj["Name"])
print("Class:", python_obj["Code"])
print("Age:", python_obj["Age"]) 



'''
run:

{'Name': 'R2D3', 'Code': 'Python', 'Age': 60}

Name: R2D3
Class: Python
Age: 60

'''

 



answered Sep 20, 2021 by avibootz

Related questions

1 answer 109 views
109 views asked Sep 20, 2021 by avibootz
1 answer 108 views
108 views asked Feb 15, 2021 by avibootz
1 answer 150 views
1 answer 207 views
1 answer 150 views
150 views asked May 24, 2022 by avibootz
1 answer 160 views
...