I think you made a mistake in order total.
import json
json_raw = """
{
"Fruits": [
{
"name": "Apple",
"quantity": 2,
"price": 24
},
{
"name": "Banana",
"quantity": 1,
"price": 17
}
]
}
"""
data = json.loads(json_raw)
print(data)
total = 0
for fruit in data ["Fruits"]:
total += fruit["quantity"] * fruit["price"]
print(f"Total : {total}")
order = {}
order["order_total"] = total
print(f"Generated json:{json.dumps(order)}")
Here the output that i got
nabil@LAPTOP:~/stackoverflow$ python3 compute-total.py
{'Fruits': [{'name': 'Apple', 'quantity': 2, 'price': 24}, {'name': 'Banana', 'quantity': 1, 'price': 17}]}
Total : 65
Generated json:{"order_total": 65}
nabil@LAPTOP:~/stackoverflow$