Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing Json dictionary
#1
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()]
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How do I skipkeys on json file read to python dictionary? BrandonKastning 3 1,828 Mar-08-2022, 09:34 PM
Last Post: BrandonKastning
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 2,167 Jul-25-2020, 06:12 AM
Last Post: LuisSatch
  saving a dictionary as json file vinay_py 6 3,031 Jun-06-2020, 05:07 PM
Last Post: vinay_py
  [split] Print JSON Dictionary to Excel? venukommu 1 2,246 Nov-15-2019, 09:33 PM
Last Post: micseydel
  Parsing json - dictionary with in dictionary krish216 6 3,574 Jul-30-2019, 10:01 PM
Last Post: cvsae
  json.dumps to keep dictionary keys batchenr 1 1,987 May-14-2019, 11:17 AM
Last Post: buran
  Trouble converting JSON String to Dictionary RBeck22 7 5,053 Mar-28-2019, 12:12 PM
Last Post: RBeck22
  parse tree to json dictionary in python maryum 0 2,569 Aug-27-2018, 04:59 AM
Last Post: maryum
  Accessing a dictionary - KeyError ?? eoins 1 3,449 Jun-06-2018, 06:14 AM
Last Post: wavic
  Accessing nested dictionary values. Plistlib, Python 2.7 williamlombard 32 20,512 Sep-29-2017, 06:46 AM
Last Post: williamlombard

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020