json.load reads a JSON document from a text file-like object and converts it into Python objects. Use it when the file contains one complete JSON value, such as an array; use json.loads for JSON text already held in a string. section 6.22 section 6.23
A practical workflow for processing JSON score files is:
- Find the .json files in the target directory and open each file for reading. section 6.23
- Call json.load on the file object; for an array of dictionaries, iterate through each dictionary and its subject-score pairs. section 6.23
- Accumulate scores by subject, then calculate the minimum, maximum, and average for the report. section 6.23
- Remember that valid JSON uses double quotes rather than Python-style single quotes. section 6.22
[{"math" : 90, "literature" : 98, "science" : 97},
{"math" : 65, "literature" : 79, "science" : 85},
{"math" : 78, "literature" : 83, "science" : 75},
{"math" : 92, "literature" : 78, "science" : 85},
{"math" : 100, "literature" : 80, "science" : 90}
]
This sample JSON array shows the list-of-dictionaries structure returned by json.load for a class score file. section 6.22
Class score analysis
Loading 9a.json produces student dictionaries such as math: 90 and science: 97. Grouping those values by subject yields reports such as science: min 75, max 97, average 86.4. section 6.22 section 6.23


