Hello all,
I am trying to import json data into my window when within actionPerformed script editor. The json data data I am importing is UTF-8 with BOM. When I print the type, it will say unicode, but I need a list or some type of datatype that I can modify the columns and remove certain keys from my list of dicts. I have already tried using ast.literal_eval and doing data = data[3:], but each of these give me different issues.
When I do ast.literal_eval i get the following error:
Traceback (most recent call last):
File "event:actionPerformed", line 6, in
File "C:\Users\jaalcid.ignition\cache\gw10.132.252.23_8088\C0\pylib\ast.py", line 49, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "C:\Users\jaalcid.ignition\cache\gw10.132.252.23_8088\C0\pylib\ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "", line 1
[
^
SyntaxError: no viable alternative at character ''
When I do data = data[3:] my list breaks into a bunch of individual Unicode segments.
Here is my json data (A list of dicts):
[
{
"Term" : "Intercept",
"Estimate" : -3.26667457316861,
"Std Error" : 4.64402760030829,
"t Ratio" : -0.703414116865231,
"Prob>|t|" : 0.496416819895656,
"Lower 95%" : -13.4881104045032,
"Upper 95%" : 6.95476125816592
},
{
"Term" : "Flow Rate",
"Estimate" : 0.00278164114479191,
"Std Error" : 0.00361876491577232,
"t Ratio" : 0.768671414014261,
"Prob>|t|" : 0.456950449399681,
"Lower 95%" : -0.00518320673268325,
"Upper 95%" : 0.0107464890222671
},
{
"Term" : "Pressure",
"Estimate" : 0.00572389801864138,
"Std Error" : 0.00422223047666328,
"t Ratio" : 1.3556574067375,
"Prob>|t|" : 0.200173228869231,
"Lower 95%" : -0.00356916860298116,
"Upper 95%" : 0.0150169646402639
},
{
"Term" : "Temperature",
"Estimate" : 0.00667732381905267,
"Std Error" : 0.00368811336635803,
"t Ratio" : 1.81049852750227,
"Prob>|t|" : 0.0953115732142802,
"Lower 95%" : -0.00144015896903698,
"Upper 95%" : 0.0147948066071423
}
]
Here is my script I have been trying to run:
import ast
idata = system.file.openFile('json')
data = system.file.readFileAsString(idata, "UTF-8")
obj = system.util.jsonDecode(data)
change = ast.literal_eval(obj)
print type(change)
I would really appreciate any help with this, I am on a big-time crunch am unsure what to try next. Thanks!