Reputation: 3504
Can anyone give me a newb tip on loading a json file into Python?
If I use:
import json
config_file = "./setpoints.json"
hvac_setpoints = json.loads(config_file)
print(hvac_setpoints)
On this setpoints.json
file:
{ "setpoint": {
"ahu_static_sp_start": 0.75,
"ahu_static_sp_min": 0.15,
"ahu_static_sp_max": 1.5,
"static_sp_trim": -0.04,
"static_sp_increase": 0.06,
"time_delay_startup": 300,
"time_delay_normal": 120,
"vav_ignore_requests": 1,
"num_of_vav_above_hi_dpr_stp": 2,
"high_vav_dpr_stp": 90}
}
I'll get an JSONDecodeError: Expecting value: line 1 column 1 (char 0)
in Python:
~\Anaconda\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~\Anaconda\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Upvotes: 0
Views: 62
Reputation: 190
I like to use a structure as follows
with open("setpoints.json", 'r') as file:
hvac_setpoints = json.load(file)
Upvotes: 2