Reputation: 37
Here is the json file
{"pre_trigger": 4, "sampling frequency": 1652, "record length": 15.0,
"sensors":
[{"model": "393B05", "serial": "46978", "sensitivity": 10030, "sensitivity_units": "mV/g", "sensor_type": "Accelerometer", "units": "g", "location": [7.01, -0.19, 0], "location_units": "m", "direction": [0, 0, 1], "trigger": true, "trigger_value": 0.005, "max_val": 0.45, "min_val": -0.45, "comments": "Inside B122 next to bookshelf", "channel": "cDAQ1Mod2/ai0"}],
[{"model": "393B05", "serial": "47085", "sensitivity": 9980, "sensitivity_units": "mV/g", "sensor_type": "Accelerometer", "units": "g", "location": [9.65, -0.19, 0], "location_units": "m", "direction": [0, 0, 1], "trigger": true, "trigger_value": 0.005, "max_val": 0.45, "min_val": -0.45, "comments": "Inside B122 under the whiteboard", "channel": "cDAQ1Mod2/ai1"}]
"parameters": {"general": [], "specific": ["Walking direction", "Person ID"]}}
I'm not one to understand coding so I don't know where this error truly is coming from. I'm running a command the following commands
daq = DAQ()
daq.load_setup('json.fname')
Which returns the property error. There are no single quotes in the json file, so I truly don't know where the problem is. Below is where the error calls back to.
def load_setup(self,fname='setup.json'):
"""
Opens the JSON file containing the setup parameters for the experiment.
Parameters
----------
fname : str
File that the parameters for the experiment were saved into (JSON file)
"""
import json
with open(fname, 'r') as setup_file:
setup_data = json.load(setup_file)
self.fs = setup_data['sampling frequency']
self.record_length = setup_data['record length']
self.sensors = setup_data['sensors']
self.parameters = setup_data['parameters']
self.pre_trigger = setup_data['pre_trigger']
Upvotes: 2
Views: 121
Reputation: 13747
You simply do not have valid JSON (there isn't anything wrong with your Python code). You're not using the array functionality correctly. A JSON array looks like this:
{"some_array": ["first item", "second item", ..., "last item"]}
it does not look like this (which is what you had and why you get the error you're getting):
{"some_array": ["first item"], ["second item"], ..., ["last item"]}
Long story short, your list items are comma delimted inside the square brackets. Here's what your JSON should look like (sensor
array fixed, and pretty-printed):
{
"pre_trigger": 4,
"sampling frequency": 1652,
"record length": 15.0,
"sensors":
[
{
"model": "393B05",
"serial": "46978",
"sensitivity": 10030,
"sensitivity_units": "mV/g",
"sensor_type": "Accelerometer",
"units": "g",
"location": [7.01, -0.19, 0],
"location_units": "m",
"direction": [0, 0, 1],
"trigger": true,
"trigger_value": 0.005,
"max_val": 0.45,
"min_val": -0.45,
"comments": "Inside B122 next to bookshelf",
"channel": "cDAQ1Mod2/ai0"
},
{
"model": "393B05",
"serial": "47085",
"sensitivity": 9980,
"sensitivity_units": "mV/g",
"sensor_type": "Accelerometer",
"units": "g",
"location": [9.65, -0.19, 0],
"location_units": "m",
"direction": [0, 0, 1],
"trigger": true,
"trigger_value": 0.005,
"max_val": 0.45,
"min_val": -0.45,
"comments": "Inside B122 under the whiteboard",
"channel": "cDAQ1Mod2/ai1"
}
],
"parameters": {
"general": [],
"specific":
[
"Walking direction",
"Person ID"
]
}
}
I recommend always keeping your JSON pretty-printed (even on disk), as it makes it easier to read/understand. Part of the appeal of the JSON format is that you can easily eyeball it as a human.
The rest of your code that you posted worked fine after this fix.
HTH.
Upvotes: 1