+ 1
Json
How to upload json in my python code
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.")



