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 203 views
203 views asked Sep 20, 2021 by avibootz
1 answer 195 views
195 views asked Feb 15, 2021 by avibootz
1 answer 242 views
1 answer 307 views
1 answer 241 views
241 views asked May 24, 2022 by avibootz
1 answer 252 views
...