Quick Example and Walk-Through JSON with Python
This is a quick to create a dictionary object , write it to a JSON file and then read back the file and convert it to a dictionary and access the items in the dictionary. Credit to : codebasics. You can check him out on Youtube In [3]:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# lets create a dictionary of books book = {} book['Tom'] = { 'name':'Tom', 'address':'1 red street, NY', 'phone':98988988 } book['Bob'] = { 'name':'Bob', 'address':'1 green street, NY', 'phone':252525885 } |
In [6]:
|
1 2 3 4 |
#import json and pass the dictionary to it import json s = json.dumps(book) s |
Out[6]:
|
1 |
'{"Bob": {"phone": 252525885, "name": "Bob", "address": "1 green street, NY"}, "Tom": {"phone": 98988988, "name": "Tom", "address": "1 red street, NY"}}' |
In [14]:…
