# Trouble Regarding Tag Values

**URL:** <https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639>\
**Category:** General Discussion\
**Tags:** ignition81\
**Created:** [January 16, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639 "2023-01-16T18:49:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/1 "2023-01-16T18:49:56Z")

</div>

Hello, I am new to ignition, and I am currently trying to get an RFID reader set up and working properly.

My RFID reader outputs its read values in a JSON format. Like this {"antennaPort":1,"epc":"E2801191A5030062744B2264","firstSeenTimestamp":1673884391510175,"peakRssi":-70,"isHeartBeat":false}

For the purposes of storing and retrieving relevant data I need it to be broken up into its respective fields. This is where I'm having a bit of trouble. I've tried fiddling with the TCP connection settings mainly the delimiter and field values and I have received some success from this, however it doesn't display my data correctly and still contains formatting characters. Is there a way for induction to interpret this correctly?

---

<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:** [January 16, 2023, 7:41pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/2 "2023-01-16T19:41:45Z")

</div>

Use a script to parse the JSON string into a python dictionary like so

```python
json = '{"antennaPort":1,"epc":"E2801191A5030062744B2264","firstSeenTimestamp":1673884391510175,"peakRssi":-70,"isHeartBeat":false}'
pyDict = system.util.jsonDecode(json)
print pyDict
print pyDict['antennaPort']

```

---

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 8:07pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/3 "2023-01-16T20:07:40Z")

</div>

Thanks for the reply.  
I've tried that and I'm running into issues using that script. I do not know how to properly run it. Also, it is not dynamic it's a fixed value.

---

<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:** [January 16, 2023, 8:14pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/4 "2023-01-16T20:14:41Z")

</div>

> [@Dalton\_Adams](#):
>
> I've tried that and I'm running into issues using that script. I do not know how to properly run it.

Please elaborate. Do you mean you don't know where to put the script, or you are getting errors?

> [@Dalton\_Adams](#):
>
> Also, it is not dynamic it's a fixed value.

I'm not sure I understand what you mean. What's not dynamic, the `json` string? That would be replaced with a tag read of the rfid tag that holds the raw json string.

---

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 8:21pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/5 "2023-01-16T20:21:20Z")

</div>

> [@dkhayes117](#):
>
> Please elaborate. Do you mean you don't know where to put the script, or you are getting errors?

I've tried running it through the tag value change event in my gateway events for my RIFD read value, but it doesn't seem to run whenever it does change.

> [@dkhayes117](#):
>
> I'm not sure I understand what you mean. What's not dynamic, the `json` string? That would be replaced with a tag read of the rfid tag that holds the raw json string.

I'm sorry I did not think it would automatically update based off the current tag being read.

---

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 8:23pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/6 "2023-01-16T20:23:58Z")

</div>

I did manually execute the code through the script console and got this result,

{u'antennaPort': 1, u'firstSeenTimestamp': 1673884391510175L, u'epc': 'E2801191A5030062744B2264', u'isHeartBeat': False, u'peakRssi': -70}  
1  
Which seems to work since it prints out the antenna value which is 1.

---

<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:** [January 16, 2023, 8:28pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/7 "2023-01-16T20:28:13Z")

</div>

Show your tag change script/setup. And format any code/scritps with the `</>` button

---

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 8:39pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/8 "2023-01-16T20:39:57Z")

</div>

```auto
#Tags Page
Script Name jsonParse
Change Triggers = Value, Quality, Timestamp
Tag Path(s) = [default]Message
################################
#Script Page
json = system.tag.read("Message")
pyDict = system.util.jsonDecode(json.value)
print pyDict
print pyDict['antennaPort']
paths = "[default]epc"
values = pyDict['epc']
system.tag.writeBlocking(paths, values)

```

I'm using the gateway events dialog on the ignition designer.

---

<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:** [January 16, 2023, 8:56pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/9 "2023-01-16T20:56:08Z")

</div>

To get the current value of the tag you are watching, change the `json` variable to

```python
json = newValue.value

```

`newValue` is a fully qualified value meaning it contains a value, quality, and timestamp items. The `.value` part gets just the value from the qualified value.

Next you need to write these values to the correct tags. To write to a tag, you must use a system function, simple assignment scripts, ie `[default]antennaPort.value = pyDict['antennaPort']` do not work.

I would loop over the dictionary, create the tag paths and write the values to those tags like so

```python
json = newValue.value
pyDict = system.util.jsonDecode(json)
paths = []
values = []
for key,value in pyDict.items():
	path.append('[Default]' + key)
	values.append(value)
system.tag.writeBlocking(paths, values)

```

Getting familiar with system functions is important when using Ignition.  
[System Functions - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/System+Functions)

---

<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:** [January 16, 2023, 8:59pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/10 "2023-01-16T20:59:13Z")

</div>

Note:  
I mentioned reading the tag to be dynamic earlier, since you are using a tag change script you will have access to the tag value without reading. If you used the script in the console for testing, you would have to read the json tag first.

---

<div class="post-metadata">

**Author:** ![Dalton\_Adams](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dalton\_Adams](https://forum.inductiveautomation.com/u/Dalton_Adams)\
**Post date:** [January 16, 2023, 9:20pm UTC](https://forum.inductiveautomation.com/t/trouble-regarding-tag-values/68639/11 "2023-01-16T21:20:31Z")

</div>

It works. Thanks for the help.
