-1

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?

B.JOE
  • 77
  • 1
  • 1
  • 8
  • 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 Answers2

1

you can use json lib to parse the string into dict.

import json
data = json.loads(string)
data[key]
goudan
  • 58
  • 4
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