Python Forum
accessing Json dictionary - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: accessing Json dictionary (/thread-23197.html)



accessing Json dictionary - lshankar - Dec-16-2019

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()]


RE: accessing Json dictionary - ndc85430 - Dec-16-2019

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.