so I am trying to load my JSON file's data to python, and then I want to use the JSON file data as a variable in python code, my way to do it is really just random guessing, can anyone here help me out?
Asked
Active
Viewed 92 times
-1
-
1`tmin = data['min_temperature']` use like this – sahasrara62 Mar 27 '19 at 01:12
-
What about searching a bit yourself first? :) You really expect this to be new problem, noone, esp. newbies, and noone, really posted, blogged, vblogged about that so fat at least once? ¯\\_(ツ)_/¯ – Marcin Orlowski Mar 27 '19 at 01:16
2 Answers
1
you can use json lib to parse the string into dict.
import json
data = json.loads(string)
data[key]

goudan
- 58
- 4
-
he already use that, he just need to lear how to access that data , `tmin = data['min_temperature']` – sahasrara62 Mar 27 '19 at 01:23
0
doing tmin = data['min_temperature']
will not work if you don't have that key.
Try tmin = data.get('min_temperature', None)
where you will get None if the key is not present.

Devesh Kumar Singh
- 20,259
- 5
- 21
- 40