# Converting a json tag to a udt or a memory tag

**URL:** <https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256>\
**Category:** Ignition\
**Created:** [March 16, 2022, 2:08pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256 "2022-03-16T14:08:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolando\_Villalobos](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rolando\_Villalobos](https://forum.inductiveautomation.com/u/Rolando_Villalobos)\
**Post date:** [March 16, 2022, 2:08pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/1 "2022-03-16T14:08:18Z")

</div>

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 } 

```

]  
}

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 16, 2022, 2:11pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/2 "2022-03-16T14:11:33Z")

</div>

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)](https://docs.inductiveautomation.com/display/DOC81/jsonGet)

---

<div class="post-metadata">

**Author:** ![Rolando\_Villalobos](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rolando\_Villalobos](https://forum.inductiveautomation.com/u/Rolando_Villalobos)\
**Post date:** [March 16, 2022, 3:49pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/3 "2022-03-16T15:49:09Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 16, 2022, 4:46pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/4 "2022-03-16T16:46:08Z")

</div>

Try

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

```

In a script:

```python
# 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']

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 16, 2022, 4:47pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/5 "2022-03-16T16:47:47Z")

</div>

Make sure your JSON string is valid as well!

> [@Rolando\_Villalobos](#):
>
> :[{“

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

```

---

<div class="post-metadata">

**Author:** ![Rolando\_Villalobos](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rolando\_Villalobos](https://forum.inductiveautomation.com/u/Rolando_Villalobos)\
**Post date:** [March 16, 2022, 4:56pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/6 "2022-03-16T16:56:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 16, 2022, 5:05pm UTC](https://forum.inductiveautomation.com/t/converting-a-json-tag-to-a-udt-or-a-memory-tag/57256/7 "2022-03-16T17:05:07Z")

</div>

At that point, I’d script it.
