JSON Read in Python
Read a JSON file into a Python dictionary using the json module.
BeginnerFile Handling ProgramsExample 6 of 20
json-read.py
1# Program to read JSON from a file23import json45filename = input("Enter JSON filename: ")67try:8 with open(filename, "r", encoding="utf-8") as f:9 data = json.load(f)10 print("Loaded JSON object:", data)11except FileNotFoundError:12 print("JSON file not found.")13except json.JSONDecodeError:14 print("Invalid JSON format.")
Output
Enter JSON filename: config.json
Loaded JSON object: {'debug': True, 'version': 1}What's going on
json.load parses the file contents into native Python objects (dicts, lists, etc.).
After this program
If the idea is still fuzzy, read Day 14: File Handling in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 file handling programs, or see every topic on Python exercises.