# Data Conversion - Java Script Expression - EtherNetIP node

**URL:** <https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787>\
**Category:** General\
**Created:** [27 April 2021 04:49 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787 "2021-04-27T04:49:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrallanH2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brallanh2/32/40801_2.png) [@BrallanH2](https://discourse.nodered.org/u/BrallanH2)\
**Post date:** [27 April 2021 04:49 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/1 "2021-04-27T04:49:20Z")

</div>

I am reading PLC tags using the Ethernet/IP node. The output is something like:

{Recipe.Ingredient[0]: 1234.5, Recipe.Ingredient[1]: 678.9}

There will be hundreds of tags.

Right now, I can read them and get a nice log.csv

I cannot, however use the tags (values).

I think I'd have the same problem if I read from log.csv as well?

I don't have a problem when I read an atomic data type. I have an entire data structure map. I just can't reference these array members as "msg.payload.Recipe.Ingredient[0]". I can reference the tag "Ingredient\_12\_Weight" by "var Ingredient12Weight=msg.payload.Ingredient\_12\_Weight".

If what I'm trying to do is possible, I think it's pretty simple for a good js programmer. It's hard to believe that it's not possible.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 April 2021 06:41 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/2 "2021-04-27T06:41:21Z")

</div>

Welcome to the forum.

Feed the message into a debug node and expand it enough that we can see the format of the data and post a screenshot here.

Have you read the node red docs page Working with Messages? It shows you how to get the path to properties from the debug pane.

---

<div class="post-metadata">

**Author:** ![BrallanH2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brallanh2/32/40801_2.png) [@BrallanH2](https://discourse.nodered.org/u/BrallanH2)\
**Post date:** [28 April 2021 19:55 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/3 "2021-04-28T19:55:20Z")

</div>

I've posted screenshots of the flow that works with Atomic tags and the flow that doesn't when I try to use Array/UDT Tags.

So far, my best solution is to use the CSV node to strip header names and then another CSV node to add new headers without "." or "[", or "]".

 ![AtomicOnly](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc18c4ec9f09c2d52f7fe6366b9123d9f6e29610.png) ![EIP_SIM_DATA](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f80364ee59fa992391320179510b1efd9189c4cf.png) ![Problem](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fac72a86f52c1e44f7c69a71ebfd3125aa30f297.png) ![Structure_Atomic](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/80a033247308bbba21b72d3f114f3d429dd241a0.png) ![Structure_Problem](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6284dfd63b930ea8830af5581c50bcb5703217b0.png)

---

<div class="post-metadata">

**Author:** ![BrallanH2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brallanh2/32/40801_2.png) [@BrallanH2](https://discourse.nodered.org/u/BrallanH2)\
**Post date:** [28 April 2021 19:59 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/4 "2021-04-28T19:59:21Z")

</div>

```auto
[{"id":"69adde37.42636","type":"tab","label":"EIP_TagError","disabled":false,"info":""},{"id":"57f9dae4.fbcfc4","type":"debug","z":"69adde37.42636","name":"EIP_Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":260,"wires":[]},{"id":"b6fcfc11.0173d","type":"function","z":"69adde37.42636","name":"EIP DATA SIM","func":"\n \nmsg.payload = {\n\"TestTag1\":1.11,\n\"TestTag2\":2.22,\n\"ActiveRecipe.Ingredient[0]\":3.33,\n\"ActiveRecipe.Ingredient[1]\":4.44,\n\"ActiveRecipe.Ingredient[2]\":5.55\n }\n \n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":260,"wires":[["57f9dae4.fbcfc4","e680d9b2.5de2a8"]]},{"id":"6e7b7fee.901cd","type":"inject","z":"69adde37.42636","name":"PokeTest","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":260,"wires":[["b6fcfc11.0173d"]]},{"id":"e680d9b2.5de2a8","type":"function","z":"69adde37.42636","name":"Structure","func":"\nlet Test1=msg.payload.TestTag1;\nlet Test2=msg.payload.TestTag2;\n\n//let Test3=msg.payload.ActiveRecipe.Ingredient[0];\n//let Test4=msg.payload.ActiveRecipe.Ingredient[1];\n//let Test5=msg.payload.ActiveRecipe.Ingredient[2];\n\n\nmsg.payload={\n \"WarpSpeedEfficiencyFactor\":Test1,\n \"HyperDriveSuperConductorTemperature (K)\":Test2,\n// \"SimpleTest1\":Test3,\n// \"SimpleTest2\":Test4,\n// \"SimpleTest3\":Test5\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":320,"wires":[["3a1826a2.a6a26a"]]},{"id":"3a1826a2.a6a26a","type":"debug","z":"69adde37.42636","name":"Structure_Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":320,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 April 2021 20:44 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/5 "2021-04-28T20:44:51Z")

</div>

If you have property names (which I think is what you mean by tags) with special characters in then you have to use the square bracket notation rather than the dot shorthand. `msg.payload` is a shorthand way of writing `msg["payload"]`. So your function needs to be something like

```auto
let Test1=msg.payload.TestTag1;
let Test2=msg.payload.TestTag2;

let Test3=msg.payload["ActiveRecipe.Ingredient[0]"];
let Test4=msg.payload["ActiveRecipe.Ingredient[1]"];
let Test5=msg.payload["ActiveRecipe.Ingredient[2]"];

msg.payload={
    "WarpSpeedEfficiencyFactor":Test1,
    "HyperDriveSuperConductorTemperature (K)":Test2,
    "SimpleTest1":Test3,
    "SimpleTest2":Test4,
    "SimpleTest3":Test5
}

return msg;

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 April 2021 20:47 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/6 "2021-04-28T20:47:51Z")

</div>

Are you sure you don't what ActiveRecipe to be an object containing an Ingredient array?

---

<div class="post-metadata">

**Author:** ![BrallanH2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brallanh2/32/40801_2.png) [@BrallanH2](https://discourse.nodered.org/u/BrallanH2)\
**Post date:** [28 April 2021 20:50 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/7 "2021-04-28T20:50:27Z")

</div>

Ingredient is an array that is a member of ActiveRecipe in the PLC which is the source of my data.

* * *

let Test1=msg.payload.TestTag1;  
let Test2=msg.payload.TestTag2;

let Test3=msg.payload["ActiveRecipe.Ingredient[0]"];  
let Test4=msg.payload["ActiveRecipe.Ingredient[1]"];  
let Test5=msg.payload["ActiveRecipe.Ingredient[2]"];

msg.payload={  
"WarpSpeedEfficiencyFactor":Test1,  
"HyperDriveSuperConductorTemperature (K)":Test2,  
"SimpleTest1":Test3,  
"SimpleTest2":Test4,  
"SimpleTest3":Test5  
}

return msg;

* * *

I had to add quotes as well but now it works. Thank you so much.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 April 2021 08:33 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/8 "2021-04-29T08:33:47Z")

</div>

> [@BrallanH2](#):
>
> Ingredient is an array that is a member of ActiveRecipe in the PLC

It may be an array in the plc but it is not an array in the code you posted.

This code that you posted

```auto
msg.payload = {
"TestTag1":1.11,
"TestTag2":2.22,
"ActiveRecipe.Ingredient[0]":3.33,
"ActiveRecipe.Ingredient[1]":4.44,
"ActiveRecipe.Ingredient[2]":5.55
    }

```

creates a property in msg.payload called `ActiveRecipe.Ingredient[0]`. If you wanted to create an array you would use

```auto
msg.payload = {
"TestTag1":1.11,
"TestTag2":2.22,
"ActiveRecipe": {"Ingredient": [3.33, 4.44, 5.55]}
}

```

Then your original code would work

```auto
let Test3=msg.payload.ActiveRecipe.Ingredient[0];
let Test4=msg.payload.ActiveRecipe.Ingredient[1];
let Test5=msg.payload.ActiveRecipe.Ingredient[2];

```

> [@BrallanH2](#):
>
> I had to add quotes as well but now it works

What quotes did you have to add?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 May 2021 08:34 UTC](https://discourse.nodered.org/t/data-conversion-java-script-expression-ethernetip-node/44787/9 "2021-05-13T08:34:17Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
