-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path83_json.py
35 lines (23 loc) · 928 Bytes
/
83_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
with open("dummyj.json", "r") as w:
rawdata = w.readlines()
w.seek(0) # taking pointer to start location
data = json.load(w)
# print("Rawdata :",rawdata) # in json format
print("Name :", data["name"]) # converted to python dict
raw = '{"5":"five","3":"three","4":"four","1":"one","2":"two"}' # json to python
dg = '{"name":"messi","Number":"10"}'
parsed = json.loads(raw) # for converting variables to json
print("Parsed :", parsed)
print("Parsed :", parsed['3'])
dic = {10: "Messi", 7: "Ronaldo", 9: "Lewandowski"}
print(dic)
converted = json.dumps(dic, sort_keys=1)
print(converted)
"""
***** Notes *****
- load() => to convert json file to python dictionary
- loads() => to convert json string/variable to python dictionary
- dump() => to convert python dictionary to json file (refer 83_writing.py)
- dumps() => to convert python dictionary to json string
"""