When a program needs to analyze data exchanged between systems, JSON provides a portable representation. Python's standard-library json module converts JSON into built-in data structures and converts Python data back into JSON-formatted strings. section 5.26 section 5.27
A practical file-processing pattern is:
- Find matching files such as scores/*.json with glob. section 5.27
- Open each file and use json.load when it contains one JSON array; use json.loads for JSON held in a string or line. section 5.27
- Organize the resulting lists and dictionaries, then calculate and print summaries. section 5.26
Class score summaries
Given files such as 9a.json and 9b.json, read each array of subject-score dictionaries, group scores by subject, and print each class's minimum, maximum, and average. Remember that valid JSON uses double quotes, not Python-style single quotes. section 5.26 section 5.27
[{"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 dictionaries illustrates the structure returned as Python data for score analysis. section 5.26



