Listing 09-16: Opening and using a JSON file

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 09\09.16 - Opening and using a JSON file.py
# Description: Opening and using a JSON file
##############################################################################

import json
from pathlib import Path
with Path("list.json").open(encoding="utf-8") as file:
    students = json.load(file)
for student in students:
    print("Name:", student["name"])
    print("Grades:", student["grades"])
    print("Average:", sum(student["grades"]) / len(student["grades"]))
    print()
Click here to download the file