-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonParsing.py
51 lines (30 loc) · 1.1 KB
/
jsonParsing.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
courses = '{"name": "PavanBisaralli","languages": [ "Java", "Python"]}'
#Loads method parse json string and it returns dictionary
dict_courses = json.loads(courses)
print(type(dict_courses))
print(dict_courses)
print(dict_courses['name'])
#get me the first language taught by trainer
# list_language = dict_courses['languages']
# print(type(list_language))
# print(list_language[0])
print(dict_courses['languages'][0])
#****** Parse content present in Json file
with open('C:\\Users\\Owner\\Documents\\course.json') as f:
data = json.load(f)
print(data)
print(type(data))
print(data['courses'][1]['title'])
print(data['dashboard']['website'])
print(type(data['dashboard']))
#price of course 'RPA'
print(type(data['courses']))
for course in data['courses']:
#print(course)
if course['title'] == "RPA":
print(course['price'])
assert course['price'] == 45
with open('C:\\Users\\Owner\\Documents\\course1.json') as fi:
data2 = json.load(fi)
assert data == data2