Python Forum

Full Version: accessing Json dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can you tell what is wring in my following code : want to access certain key values from a json file (in dictionary format) and store it to a variable.

if rain:

key_values=[[data['state'] for data in response.json['records']['data'] if 'state' in data and str(data ['rainyDate']).lower()== str(rain).lower()]
You haven't given us enough information to help you. Why do you assume something is wrong? Do you get errors when running this code? If so, what are they? Also, it would probably help to provide us with a sample of the JSON you have, so we can see whether you're navigating it properly. You mention that the JSON is stored in a file, yet your code refers to a variable called response, which to me suggests an HTTP response, so which is it really?

In short: remember that we're not at the computer with you, so you need to provide us with as much information as possible.