+ 1

Json

How to upload json in my python code

15th Nov 2025, 10:09 AM
Michael Odu
Michael Odu - avatar
1 Answer
+ 4
import json file_path = 'data.json' try: with open(file_path, 'r') as file: data = json.load(file) # The 'data' variable now holds your JSON data as a Python dictionary/list print("Successfully loaded JSON data:") print(data) print(f"The person's name is: {data['name']}") # Example access except FileNotFoundError: print(f"Error: The file '{file_path}' was not found.") except json.JSONDecodeError: print(f"Error: The file '{file_path}' is not a valid JSON file.")
15th Nov 2025, 2:30 PM
BroFar
BroFar - avatar