-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaner.py
32 lines (24 loc) · 812 Bytes
/
cleaner.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
import json
temp = {"name": "Bob", "languages": "English", "numbers": [2, 1.6, "null"]}
with open("recipe.json","r") as f:
raw = json.load(f)
print(len(raw))
#func to filter attributes
def filter_attributes(item):
out = {}
#attributes to keep
out["name"] = item["name"]
out["group"] = item["group"]["name"]
out["subgroup"] = item["subgroup"]["name"]
keep = ["energy","ingredients","products"]
for category in keep:
out[category] = item[category]
return out #returns contents as dictionary
#cleaning out unneeded attributes
clean = {}
uniques = {"groups":[],"sub-groups":[]}
for item in raw:
if not raw[item]["hidden"]:
clean[item] = filter_attributes(raw[item])
with open("cleaned.json","w") as output:
json.dump(clean,output,indent=4)