Using the built-in library json
you can decode JSON into Python objects.
If you use this data:
[
{"id": "1","student":"John", "dt": "1997-01-01 07:00:02", "score1": "38.28"},
{"id": "2", "student":"Jane", "dt": "1997-01-01 07:00:02", "score1": "32.35"},
{"id": "3", "student":"Richard", "dt": "1997-01-10 10:00:00", "score3": "22.92"}
]
Note the [...]
and ,
in the data so it loads as a list.
Then the script below could do the job.
import json
from math import fsum
data = json.load(open("data.json")) # Load the data
sums = {}
for person in data: # Loop over pieces of data
# Add any names starting with "score" to sums
for key in person.keys(): # Loop over names
if not key[:5] == "score":
continue # No, not starting with score, skip it
# Use math.fsum to add the value known to the score, and set it.
sums[key] = fsum([sums.get(key, 0.0), float(person[key])])
for k, v in sums.items():
# Print out the data
print("%s: %.02f" % (k, v))
I added explanations in the comments. Tested in IDLE 3.6.1.