-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
40 lines (35 loc) · 1.18 KB
/
script.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
import json
# Load JSON data from file with one JSON object per line
updated_data = []
with open('epi_r.json', 'r') as file:
for line in file:
try:
item = json.loads(line)
updated_data.append(item)
except json.JSONDecodeError:
print("Skipping invalid JSON line.")
# Prepare the updated data
transformed_data = []
for item in updated_data:
tags = {
"vegetarian": item.get("vegetarian", False),
"gluten_free": item.get("gluten_free", False),
"dairy_free": item.get("dairy_free", False),
"quick": item.get("quick", False),
"low_carb": item.get("low_carb", False),
"high_protein": item.get("high_protein", False)
}
updated_item = {
"title": item.get("title"),
"rating": item.get("rating"),
"calories": item.get("calories"),
"protein": item.get("protein"),
"fat": item.get("fat"),
"sodium": item.get("sodium"),
"tags": tags
}
transformed_data.append(updated_item)
# Save the updated JSON data
with open('epi_r_updated.json', 'w') as file:
json.dump(transformed_data, file, indent=4)
print("Data updated successfully!")