import json
# Converting python object and writing into json file
data = {
"name": "Satyam kumar",
"place": "patna",
"skills": ["Raspberry pi", "Machine Learning", "Web Development"],
"email": "xyz@gmail.com",
"projects": ["Python Data Mining", "Python Data Science"],
"player": True}
with open("data2.json", "w") as f:
json.dump(data, f)
# Converting python object into json string.
res = json.dumps(data)
print(res)
# loads the created json file
with open("data.json", "r") as f:
print(json.load(f))
# json string, after parsing becomes a python dict
data = """{
"name" : "abdur",
"natur" : "space",
"favterm" : "infinity",
"lvoe" : true
}"""
pasa = json.loads(data)
print(pasa)
print(pasa["name"])
Comments
Post a Comment
Write something to CodeWithAbdur!