I am trying to run the following code on the Script Console:
def removeDuplicateKeys():
import json
x = '{"name":"Lucca"}'
y = json.loads(x)
return y
removeDuplicateKeys()
However, I get an error saying the following:
Traceback (most recent call last):
File "", line 7, in
File "", line 4, in removeDuplicateKeys
AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'loads'
I noticed that when i run the same exact code on a different project on the same gateway, it is able to execute properly. Any ideas?
move the import outside of the def. That doesn't really explain why you would be getting this error. There seems to be some type of scope leakage going on, the error is obviously referring to the json.loads() function, so probably has to do with the import not occurring properly.
It's also just best practice to do imports outside of any defs