Converting a json tag to a udt or a memory tag

I have a tag that is coming in as a json format but I’m wondering if there is a way to convert this json tag to inidividual memory tags?
here is the property is of the tag
{
“accessRights”: “Read_Only”,
“dataType”: “String”,
“enabled”: true,
“name”: “iotgateway1”,
“tagType”: “AtomicTag”
}

here is the value of the tag

{
“timestamp”: 1647439655152,
“values”: [

 {"id": "Simulation Examples.Functions.Ramp1", "v": 51, "q": true, "t": 1647439655141 } ,

 {"id": "Simulation Examples.Functions.Ramp2", "v": 173.25, "q": true, "t": 1647439655141 } ,

 {"id": "Simulation Examples.Functions.Ramp3", "v": 135, "q": true, "t": 1647439655141 } 

]
}

You’ll want to write a script to convert the JSON string to a dictionary then write to the tags that represent the JSON keys. I haven’t tried this myself, but you might can use the jsonGet expression function jsonGet - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

Willing to help with that format?

Here is my mqtt engine path [MQTT Engine]iotgateway2
I want to get the value for the first tag and he is the json output

{“timestamp”:1647445423421,“values”:[{“id”:“Simulation Examples.Functions.Ramp2”,“v”:179.25,“q”:true,“t”:1647445415223}

I tried this as an tag expression and it seems to fail.
jsonGet(’{"[MQTT Engine]iotgateway2":{“v”}}’,“v”)

Try

jsonGet({[MQTT Engine]iotgateway2}, 'values[0].v')

In a script:

# Read the tag and get its value
string = system.tag.readBlocking(['[MQTT Engine]iotgateway2'])[0].value

# Decode the string
dictOut=system.util.jsonDecode(string)

for val in dictOut['values']:
	print val['id'], val['v'], val['q']
2 Likes

Make sure your JSON string is valid as well!

{
  "timestamp": 1647445423421,
  "values": {
    "id": "Simulation Examples.Functions.Ramp2",
    "v": 179.25,
    "q": true,
    "t": 1647445415223
  }
}

thanks Jordan that worked!

One last question, lets say I start to add more tags to the json file. How can I adjust the jsonGet to look for specific tags and its values only since the json file is going to have several tags and I wanted to associate those tags to individual expression tags?

example of json.
{
“timestamp”: 1647449695415,
“values”: [

 {"id": "Simulation Examples.Functions.Ramp2", "v": 168, "q": true, "t": 1647449695240 } ,

 {"id": "Simulation Examples.Functions.Ramp3", "v": 225, "q": true, "t": 1647449695240 } 

]
}

How I would like to have it configured in Ingition as a tag
tag name: Simulation Examples.Functions.Ramp2
tag value: 168

tag name: Simulation Examples.Functions.Ramp3
tag value: 225

At that point, I’d script it.