-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (38 loc) · 1006 Bytes
/
Copy pathmain.py
File metadata and controls
56 lines (38 loc) · 1006 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
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
52
53
54
55
56
import json
from pathlib import Path
print("welcome to JSON Data Explorer")
print("Choose a dataset:")
print("1. Albums")
print("2. Comments")
print("3. posts")
print("4. users")
choice = input("Enter your optin:")
files = {
"1": "albums.json",
"2": "comments.json",
"3": "posts.json",
"4": "users.json",
}
if choice not in files:
print("Invalid option selected")
exit()
selected_file = files[choice]
file_path = Path("data") / selected_file
f = open(file_path)
data = json.load(f)
f.close()
print(json.dumps(data,indent = 4))
ask = input("Do you want specific data? (yes/no):")
if ask.lower() == "yes":
print("Available fields:")
print(data[0].keys())
field = input("Which field do you want to see? ")
if field not in data[0]:
print("Invalid field selected")
exit()
for item in data:
if field in item:
print(item[field])
else:
print("Okay, exiting...")
print("Thanks for using JSON Data Explorer")