I am trying to retrieve the records from an API and eventually want to store them in a dataframe so that I can do some analytics. But I am getting the following error:
for item in json_obj["records"]:
KeyError: 'records'
Code:
import urllib.request
import json
import urllib.request
url = 'https://eservices.mas.gov.sg/api/action/datastore/search.json?resource_id=7f1363cc-3875-4e03-a389-fc47342bb840&limit=5'
response = urllib.request.urlopen(url).read().decode('UTF-8')
json_obj = json.loads(response)
for item in json_obj["records"]:
print(item[end_of_month'])
print(item['preliminary'])
print(item['cards_main'])
'records'key in thejson_objdictionary. Beyond that, what do you think anyone can tell you? Do you know what keys it does have? Have you tried printing them out? Doing any other debugging?console.log(Object.keys(json_obj))should make it easy to see.json_obj["result"]["records"]print(json_obj.keys())in that case... Or better still, what I use to explore data in python:from pprint import pprintthen simplypprint(json_obj)