Get and update a json document with a component


Is there a component which can allow user to read a json document and change elements ?
I store configuration in json format in a mysql database.
I would like to create an interface to show and update this config.

you could user system.util.jsonDecode - Ignition User Manual 8.1 - Ignition Documentation
to get the data display it in a textarea and convert it back to jsono with system.util.jsonEncode

If you don’t want people to be able to restructure the whole content itself, I would create forms to enter and edit the config which would then update the json with a save button in a defined manner.


Yes, it could be like a form which can be completed by user (admin in a first time). In my situation, the json is stored in a mysql DB.

If you are using a fixed structure, why not just make it into sql columns?

Because JSON is more adaptable. If you want to add a new variable, you don’t have to add a column.
With perspective it’s more easy to use JSON, you just have to convert in dictionary.

If you are using a form i guessing it wont change all to much over time…
So i would personally not go for json inside a db here.
Ive used json in db’s too for things that vary a lot (idk like a style property) but if its a fixed structure, columns are easier imho. unless i guess you always need all the data in the json all the time, then i doesnt matter to much i suppose

1 Like

I’ve created some embedded view with bi-directionnal property bindings to read my json from mysql and update it. It’s not dynamic for instance because my json structure is always the same.

Now I have a problem :
When I want to encode my updated json store in view.params.config : system.util.jsonEncode(config) return NULL.
I don’t know why.

My config variable in view.params:

It only returns null if you the entry is null. So you are not selecting the config property correct.

in a script it should look like
system.util.jsonEncode(self.view.params.config) or something

The input is correct. I checked it.

My script below :

config = self.view.params.config
self.view.custom.notencoded = config

jsonString = system.util.jsonEncode(config)
self.view.custom.encoded = jsonString
inputs = {'usage_id':self.view.params.usage_id,'config':config}
#Update to MySQL DB
result = usage.update(inputs)

Result :


Try this:

from com.inductiveautomation.ignition.common import TypeUtilities
jsonString = str(TypeUtilities.pyToGson(self.view.params.config))

inputs = {'usage_id':self.view.params.usage_id,'config':jsonString}

result = usage.update(inputs)


Then when you put it back:

self.view.params.config = system.util.jsonDecode(jsonStringFromDB)
1 Like

It works.
Thanks !