Use Python’s standard-library json module to move between JSON-formatted data and Python objects. JSON is a data representation rather than a Python data type, so reading or creating it requires conversion. section 6.22 section 6.23
Choose the operation that matches the input:
- Use json.load with a file object containing one JSON value, such as an array. section 6.23
- Use json.loads when JSON text is already in a string, such as a line read from a file. section 6.23
- Use json.dump or json.load to move between Python data structures and JSON-formatted file data. section 6.30
Analyze JSON score files
Implement print_scores(directory) by finding matching .json files, loading each file’s array of dictionaries, collecting subject scores in a nested dictionary, and printing each class’s minimum, maximum, and average. Remember that valid JSON uses double quotes, not Python-style single quotes. section 6.22 section 6.23
[{"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}
]
A JSON array of student dictionaries becomes a Python combination of built-in structures that can be traversed and aggregated. section 6.22



