Skip to content

Instantly share code, notes, and snippets.

@rameshbaskar
Created October 24, 2021 13:38
Show Gist options
  • Save rameshbaskar/23ded5e6f5553fadc7425cb6c2febd7e to your computer and use it in GitHub Desktop.
Save rameshbaskar/23ded5e6f5553fadc7425cb6c2febd7e to your computer and use it in GitHub Desktop.
Python - Reading data from a JSON file
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