- Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathP51_PythonJSON.py
More file actions
Latest commit
25 lines (21 loc) · 683 Bytes
/
Copy pathP51_PythonJSON.py
File metadata and controls
25 lines (21 loc) · 683 Bytes
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
# Author: OMKAR PATHAK
# This example shows how to use Python with JSON
importjson
# For storing on json format
defstoreJSON(fileName, data= {}):
withopen(fileName, 'w') asfd:
json.dump(data, fd, indent=4, separators= (',', ': '))
# For loading data from a JSON file
defloadJSON(fileName):
withopen(fileName) asfd:
data=json.load(fd)
print(data)
returndata
if__name__=='__main__':
data=loadJSON('example.json')
print(data['menu']['value']) # File
data['menu']['value'] ='movie'
storeJSON('example.json', data)
print()
loadJSON('example.json')
print(data['menu']['value']) # movie