Created
October 24, 2021 13:38
-
-
Save rameshbaskar/23ded5e6f5553fadc7425cb6c2febd7e to your computer and use it in GitHub Desktop.
Python - Reading data from a JSON file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
# No need to specify the "r" (ie. open the file in read-only mode) as it is the default | |
def parse_json(json_file_path): | |
json_data = None | |
try: | |
file = open(json_file_path, "r") | |
json_data = json.load(file) | |
except: | |
print("Something went wrong while opening JSON file: " + json_file_path) | |
finally: | |
file.close() | |
return json_data | |
data = parse_json("sample.json") | |
for record in data["key"]: | |
print(record) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment