JSON module in Python

    

   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

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes