# MQTT array, display only 1 value

**URL:** <https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240>\
**Category:** Maker\
**Tags:** perspective\
**Created:** [January 13, 2024, 1:33pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240 "2024-01-13T13:33:09Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 1:33pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/1 "2024-01-13T13:33:09Z")

</div>

Hi there,

Using MQTT Engine, im receiving an array of string, which I want to display only one of the string from the array. Im trying to index the array by using "[2]", but it displays all the strings in the array anyway. How can i display only ie. number 2?

The MQTT variable:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/7/b77f8e56e60762b703d25ef1013bc50ec030daad.png)

Indexing and displaying the array, still gives all values.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6e8580bb243e5b82cc9085593f32b498df790033.png)

Any ideas? 🙂

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 13, 2024, 1:43pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/2 "2024-01-13T13:43:35Z")

</div>

Have you tried using a script transform on the value? Perhaps something like `list(value)[1]` would work.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 1:44pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/3 "2024-01-13T13:44:19Z")

</div>

It's probably nothing to do with the problem but you've shown the **Hops names** variable content but your binding is for **Hops use**.

I've created a string array memory tag and can access each element as you are without difficulty. Can you show us the contents of Hops use?

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 3:40pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/4 "2024-01-13T15:40:47Z")

</div>

Hi, your right i missed that. But the problem is the same for both, and also more variables.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff16c643e5140d61a3aa1a35671a03ca2a9a5e81.png)

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 3:43pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/5 "2024-01-13T15:43:42Z")

</div>

Well, i'm no good with the scripting part... How should I do this? 🙂

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e0f31e5abefef7a3255f6f34c96f2d5fdd9ee4f3.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/6 "2024-01-13T15:47:00Z")

</div>

You've created a Script Transform. Justin's given you an Expression Transform.

Remove the `[1]` from your tag path.  
Delete the script transform.  
Create an expression transform.  
Paste his code straight in and that's it.

Think of expressions as being like Excel functions. It's not a program script but rather one or more functions or operations on variables and it just returns one result (or result set).

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 3:50pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/7 "2024-01-13T15:50:25Z")

</div>

Thank you 🙂

I get this error 😕

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/f/8f79a465eb84f6d9110015b70769a35230f46f4f.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 4:06pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/8 "2024-01-13T16:06:13Z")

</div>

Hover over the Error\_Configuration error to read what the problem is.

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 4:09pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/9 "2024-01-13T16:09:01Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/9/99f9ebf681fa7d78cba6d7b0caff8ec47f47e63f.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/10 "2024-01-13T16:11:59Z")

</div>

Sorry, I'm having a bad day. `list()` is a script function, not an expression function. Your first attempt was right but Justin, I think, missed the `{ }` braces. Try modifying the script to,  
`list({value})[1]`

`{value}` is what's passed into the transform from the previous operation.

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/11 "2024-01-13T16:16:14Z")

</div>

Uhm, different error this time as you see, list function is unknows 😕

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e705008c75f12c61f01334576dc5e65e75f88e2f.png)

As script:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/d/bd0d6bb752af5e5bfd7dc85ccaf871a64c266a96.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/12 "2024-01-13T16:16:59Z")

</div>

I modified my previous post. It may be better to wait on someone else to respond!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 13, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/13 "2024-01-13T16:22:05Z")

</div>

Question for anyone else reading the thread:

Vidar's MQTT tags display in Tag Browser are displayed as an array / list like this:  
[![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff16c643e5140d61a3aa1a35671a03ca2a9a5e81.png) ](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff16c643e5140d61a3aa1a35671a03ca2a9a5e81.png)

When I created a string array for testing it shows up like this:  
 ![String array](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/9/a9e46b52ac7cdaec50976dadba93d95aa61ef900.png)

Can you explain why?

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 4:26pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/14 "2024-01-13T16:26:27Z")

</div>

Thats strange... Any chance that this has something to do with MQTT to do? Im publishing data from Nodered/MQTT. The data from nodered looks like this (array):

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7a0395966d6753eda51dae7711ef1d23637f13af.png)

Then, it is sent via MQTT node. Not sure what is done with the data inside this node. Maybe its sent as 1 complete string, instead of array?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/3/63b0f944a0ff9fc6897d0809610065ab349114ba.png)

Or maybe not, when i subscribe to this topic it is displayed as array:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/18fa4e4ea16c081a306fc8011dfa919ff10064c0.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/5/d53543127e8838648e09dca6737ab45d1ec29861.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 13, 2024, 4:52pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/15 "2024-01-13T16:52:52Z")

</div>

I would expect this expression transform to work:

```auto
{value}[1]

```

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 13, 2024, 5:12pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/16 "2024-01-13T17:12:38Z")

</div>

Check the data type on the actual tag you're getting. I suspect it's passing it as a JSON string and not an array.

Edit: If this is the case, you'll need something like:

```auto
jsonGet({value},'[1]')

```

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/17 "2024-01-13T17:55:09Z")

</div>

Thanks, not sure where to check which data type is recieved...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e188ed36df884248f3feba64e6eef4236301b7b6.png)

No luck with the jsonGet either... 😕

EDIT:  
Actually, this worked! 🙂

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bb9d6c554cf623431534d5fc055fd7c336b22b16.png)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 13, 2024, 6:14pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/18 "2024-01-13T18:14:06Z")

</div>

Glad it worked for you.  
I just realized I should have left off the return (I was mixing up expressions with scripting there for a bit). I'll edit it so no one else gets confused by it either.

Usually there's a 3rd column that shows what your datatype is that I'm not seeing in your screenshot.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/f/6fb9807c4d56ac41aa8195cd78ceebb11883cbef.png)

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [January 13, 2024, 6:17pm UTC](https://forum.inductiveautomation.com/t/mqtt-array-display-only-1-value/84240/19 "2024-01-13T18:17:26Z")

</div>

Ah! Data type column wasn't active, but it says its a string

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/3/b3d7905eab12566956fc69a13c4d4e18780076aa.png)
